Exemple #1
0
def make_plot(name, glyph):
    glyph_renderer = GlyphRenderer(
        data_source=source,
        xdata_range=xdr,
        ydata_range=ydr,
        glyph=glyph,
    )

    pantool = PanTool(dataranges=[xdr, ydr], dimensions=["width", "height"])
    zoomtool = ZoomTool(dataranges=[xdr, ydr], dimensions=("width", "height"))

    plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
    xaxis = LinearAxis(plot=plot, dimension=0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    xgrid = Rule(plot=plot, dimension=0)
    ygrid = Rule(plot=plot, dimension=1)

    plot.renderers.append(glyph_renderer)
    plot.tools = [pantool, zoomtool]

    sess = session.PlotServerSession(username="******",
                                     serverloc="http://localhost:5006",
                                     userapikey="nokey")
    sess.add(plot, glyph_renderer, xaxis, yaxis, xgrid, ygrid, source, xdr,
             ydr, pantool, zoomtool)
    sess.use_doc(name)
    sess.store_all()
Exemple #2
0
def generate_embed_test():
    """this generates a new plot and uses the script inject to put it
    into a page running this repeatedly will fill up your redis DB
    quickly, but it allows quick iteration

    """

    from numpy import pi, arange, sin, cos
    import numpy as np

    from bokeh.objects import (
        Plot, DataRange1d, LinearAxis, Rule,
        ColumnDataSource, GlyphRenderer, 
        PanTool, ZoomTool, PreviewSaveTool)

    from bokeh.glyphs import Circle
    from bokeh import session

    x = arange(-2*pi, 2*pi, 0.1)
    y = sin(x)
    z = cos(x)
    widths = np.ones_like(x) * 0.02
    heights = np.ones_like(x) * 0.2


    source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths,
                                    heights=heights))

    xdr = DataRange1d(sources=[source.columns("x")])
    ydr = DataRange1d(sources=[source.columns("y")])

    circle = Circle(x="x", y="y", fill="red", radius=5, line_color="black")

    glyph_renderer = GlyphRenderer(
        data_source = source,
        xdata_range = xdr,
        ydata_range = ydr,
        glyph = circle)


    pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"])
    #zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height"))
    previewtool = PreviewSaveTool(dataranges=[xdr,ydr], dimensions=("width","height"))

    plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source],
                border= 80)
    xaxis = LinearAxis(plot=plot, dimension=0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    xgrid = Rule(plot=plot, dimension=0)
    ygrid = Rule(plot=plot, dimension=1)

    plot.renderers.append(glyph_renderer)
    plot.tools = [pantool, previewtool]

    sess = session.PlotServerSession(
        username="******", 
        serverloc="http://localhost:5006", userapikey="nokey")
    sess.use_doc("glyph2")
    sess.add(plot, glyph_renderer, xaxis, yaxis, xgrid, ygrid, source, 
             xdr, ydr, pantool, previewtool)
    sess.plotcontext.children.append(plot)
    sess.plotcontext._dirty = True
    # not so nice.. but set the model doens't know
    # that we appended to children
    sess.store_all()

    if app.debug:
        slug = hemlib.slug_json()
        static_js = hemlib.slug_libs(app, slug['libs'])
        hemsource = os.path.join(app.static_folder, "coffee")
        hem_js = hemlib.coffee_assets(hemsource, "localhost", 9294)
        hemsource = os.path.join(app.static_folder, "vendor",
                                 "bokehjs", "coffee")
        hem_js += hemlib.coffee_assets(hemsource, "localhost", 9294)
    else:
        static_js = ['/bokeh/static/js/application.js']
        hem_js = []
    return render_template("generate_embed_test.html", jsfiles=static_js, hemfiles=hem_js, 
                           plot_scr=plot.script_inject())
Exemple #3
0
xdr = Range1d(start=-2 * pi, end=2 * pi)
ydr = Range1d(start=-1, end=1)

line = Line(xs="xs", ys="ys", line_color="blue", line_width=2)
glyph_renderer = GlyphRenderer(data_source=source,
                               xdata_range=xdr,
                               ydata_range=ydr,
                               glyph=line)

pantool = PanTool(dataranges=[xdr, ydr], dimensions=("width", "height"))
zoomtool = ZoomTool(dataranges=[xdr, ydr], dimensions=("width", "height"))

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Rule(plot=plot, dimension=0)
ygrid = Rule(plot=plot, dimension=1)

plot.renderers.append(glyph_renderer)
plot.tools = [pantool, zoomtool]

import sys

demo_name = "line"
if len(sys.argv) > 1 and sys.argv[1] == "server":
    sess = session.PlotServerSession(username="******",
                                     serverloc="http://localhost:5006",
                                     userapikey="nokey")
    sess.use_doc(demo_name)
    sess.add(plot, glyph_renderer, xaxis, yaxis, xgrid, ygrid, source, xdr,
             ydr, pantool, zoomtool)