示例#1
0
def new_source():
    return dict(
        curve=CDS(dict(x=[], base_x=[], y=[])),
        lines=CDS(dict(line_x=[], line_y=[], radius_x=[], radius_y=[])),
        circle_point=CDS(dict(x=[], y=[], r=[])),
        circleds=CDS(dict(x=[], y=[]))
    )
示例#2
0
def create_plot(foos, title='', r=1, y_range=None, period=pi / 2, cfoos=None):
    if y_range is None:
        y_range = [-2, 2]

    # create new figure
    p = figure(title=title,
               width=800,
               height=300,
               x_range=[-2.5, 9],
               y_range=y_range)
    p.xgrid.bounds = (-2, 2)
    p.xaxis.bounds = (-2, 2)

    _sources = []
    cx, cy = 0, 0
    for i, foo in enumerate(foos):
        sources = new_source()
        get_new_sources(x, foo, sources, cfoos[i], cx, cy, i == 0)
        cp = sources['circle_point'].data
        cx, cy = cp['x'][0], cp['y'][0]

        if i == 0:
            # compute the full fourier eq
            full_y = sum([foo(x) for foo in foos])
            # replace the foo curve with the full fourier eq
            sources['curve'] = CDS(dict(x=x, base_x=base_x, y=full_y))
            # draw the line
            p.line(
                'base_x',
                'y',
                color="orange",
                line_width=2,
                source=sources['curve'],
                legend="4sin(x)/pi + 4sin(3x)/3pi + 4sin(5x)/5pi + 4sin(7x)/7pi"
            )

        if i == len(foos) - 1:
            # if it's the last foo let's draw a circle on the head of the curve
            sources['floating_point'] = CDS({'x': [shift], 'y': [cy]})
            p.line('line_x',
                   'line_y',
                   color=palette[i],
                   line_width=2,
                   source=sources['lines'])
            p.circle('x',
                     'y',
                     size=10,
                     line_color=palette[i],
                     color=palette[i],
                     source=sources['floating_point'])

        # draw the circle, radius and circle point realted to foo domain
        create_circle_glyphs(p, palette[i], sources)
        _sources.append(sources)

    return p, _sources
示例#3
0
def new_source():
    return dict(curve=CDS(), lines=CDS(), circle_point=CDS(), circleds=CDS())