Exemplo n.º 1
0
def make_plot(xname, yname, xax=False, yax=False, text=None):
    plot = Plot(
        x_range=xdr, y_range=ydr, data_sources=[source], background_fill="#ffeedd",
        width=250, height=250, border_fill='white', title="", border_symmetry="", min_border=2)
    if xax:
        xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
    if yax:
        yaxis = LinearAxis(plot=plot, dimension=1, location="left")
    xgrid = Grid(plot=plot, dimension=0)
    ygrid = Grid(plot=plot, dimension=1)
    circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color")
    circle_renderer = Glyph(
        data_source = source,
        xdata_range = xdr,
        ydata_range = ydr,
        glyph = circle,
    )
    plot.renderers.append(circle_renderer)
    plot.tools = [pan, zoom]
    if text:
        text = " ".join(text.split('_'))
        text = Text(
            x={'field':'xcenter', 'units':'screen'},
            y={'field':'ycenter', 'units':'screen'},
            text=text, angle=pi/4, text_font_style="bold", text_baseline="top",
            text_color="#ffaaaa", text_alpha=0.5, text_align="center", text_font_size="28pt")
        text_renderer = Glyph(
            data_source=text_source,
            xdata_range = xdr,
            ydata_range = ydr,
            glyph = text,
        )
        plot.data_sources.append(text_source)
        plot.renderers.append(text_renderer)
    return plot
Exemplo n.º 2
0
 def make_downloads_plot(self, source):
     xdr = DataRange1d(sources=[source.columns("dates")])
     ydr = DataRange1d(sources=[source.columns("downloads")])
     title = "%s downloads" % self.modelform.installer
     plot = Plot(title=title,
                 data_sources=[source],
                 x_range=xdr,
                 y_range=ydr,
                 width=600,
                 height=400)
     line = Line(x="dates", y="downloads", line_color="blue")
     line_glyph = Glyph(data_source=source,
                        xdata_range=xdr,
                        ydata_range=ydr,
                        glyph=line)
     plot.renderers.append(line_glyph)
     circle = Circle(x="dates", y="downloads", fill_color="red")
     circle_glyph = Glyph(data_source=source,
                          xdata_range=xdr,
                          ydata_range=ydr,
                          glyph=circle)
     plot.renderers.append(circle_glyph)
     hover = HoverTool(plot=plot, tooltips=dict(downloads="@downloads"))
     plot.tools.append(hover)
     xformatter = DatetimeTickFormatter(formats=dict(months=["%b %Y"]))
     yformatter = BasicTickFormatter(precision=None, use_scientific=False)
     xaxis = DatetimeAxis(plot=plot, dimension=0, formatter=xformatter)
     yaxis = LinearAxis(plot=plot, dimension=1, formatter=yformatter)
     xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
     ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
     return plot
Exemplo n.º 3
0
def make_plot(title, xname, yname):
    plot = Plot(x_range=xdr,
                y_range=ydr,
                title=title,
                plot_width=400,
                plot_height=400,
                border_fill='white',
                background_fill='#e9e0db')

    xaxis = LinearAxis(axis_line_color=None)
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis(axis_line_color=None)
    plot.add_layout(yaxis, 'left')

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

    line = Line(x='x', y='y', line_color="#666699", line_width=2)
    plot.add_glyph(lines_source, line)

    circle = Circle(x=xname,
                    y=yname,
                    size=12,
                    fill_color="#cc6633",
                    line_color="#cc6633",
                    fill_alpha=0.5)
    plot.add_glyph(circles_source, circle)

    return plot
Exemplo n.º 4
0
def make_plot():
    xdr = DataRange1d(sources=[source.columns("dates")])
    ydr = DataRange1d(sources=[source.columns("downloads")])

    plot = Plot(title="Product downloads",
                x_range=xdr,
                y_range=ydr,
                plot_width=400,
                plot_height=400)

    line = Line(x="dates", y="downloads", line_color="blue")
    plot.add_glyph(source, line)

    circle = Circle(x="dates", y="downloads", fill_color="red")
    plot.add_glyph(source, circle)

    xaxis = DatetimeAxis()
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis()
    plot.add_layout(yaxis, 'left')

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

    plot.add_tools(HoverTool(tooltips=dict(downloads="@downloads")))

    return plot, source
Exemplo n.º 5
0
def make_plot():
    source = ColumnDataSource(
        dict(
            dates=[date(2014, 3, i) for i in [1, 2, 3, 4, 5]],
            downloads=[100, 27, 54, 64, 75],
        ))
    xdr = DataRange1d(sources=[source.columns("dates")])
    ydr = DataRange1d(sources=[source.columns("downloads")])
    plot = Plot(title="Product downloads",
                data_sources=[source],
                x_range=xdr,
                y_range=ydr,
                width=400,
                height=400)
    line = Line(x="dates", y="downloads", line_color="blue")
    line_glyph = Glyph(data_source=source,
                       xdata_range=xdr,
                       ydata_range=ydr,
                       glyph=line)
    plot.renderers.append(line_glyph)
    circle = Circle(x="dates", y="downloads", fill_color="red")
    circle_glyph = Glyph(data_source=source,
                         xdata_range=xdr,
                         ydata_range=ydr,
                         glyph=circle)
    plot.renderers.append(circle_glyph)
    hover = HoverTool(plot=plot, tooltips=dict(downloads="@downloads"))
    plot.tools.append(hover)
    xaxis = DatetimeAxis(plot=plot, dimension=0)
    yaxis = LinearAxis(plot=plot, dimension=1)
    xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
    ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
    return plot, source
Exemplo n.º 6
0
def test_Circle():
    marker = Circle()
    yield check_marker, marker
    assert marker.radius == None
    yield check_fill, marker
    yield check_line, marker
    yield check_props, marker, ["radius"], MARKER, FILL, LINE
Exemplo n.º 7
0
def make_plot(xname, yname, xax=False, yax=False, text=None):
    plot = Plot(x_range=xdr,
                y_range=ydr,
                background_fill="#efe8e2",
                border_fill='white',
                title="",
                min_border=2,
                border_symmetry=None,
                plot_width=250,
                plot_height=250)

    circle = Circle(x=xname,
                    y=yname,
                    fill_color="color",
                    fill_alpha=0.2,
                    size=4,
                    line_color="color")
    plot.add_glyph(source, circle)

    xticker = BasicTicker()
    if xax:
        xaxis = LinearAxis()
        plot.add_layout(xaxis, 'below')
        xticker = xaxis.ticker
    plot.add_layout(Grid(dimension=0, ticker=xticker))

    yticker = BasicTicker()
    if yax:
        yaxis = LinearAxis()
        plot.add_layout(yaxis, 'left')
        yticker = yaxis.ticker
    plot.add_layout(Grid(dimension=1, ticker=yticker))

    plot.add_tools(PanTool(), WheelZoomTool())

    if text:
        text = " ".join(text.split('_'))
        text = Text(x={
            'field': 'xcenter',
            'units': 'screen'
        },
                    y={
                        'field': 'ycenter',
                        'units': 'screen'
                    },
                    text=[text],
                    angle=pi / 4,
                    text_font_style="bold",
                    text_baseline="top",
                    text_color="#ffaaaa",
                    text_alpha=0.7,
                    text_align="center",
                    text_font_size="28pt")
        plot.add_glyph(text_source, text)

    return plot
Exemplo n.º 8
0
def large_plot():
    source = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1]))

    xdr = Range1d(start=0, end=1)
    xdr.tags.append("foo")
    xdr.tags.append("bar")

    ydr = Range1d(start=10, end=20)
    ydr.tags.append("foo")

    plot = Plot(x_range=xdr, y_range=ydr)

    ydr2 = Range1d(start=0, end=100)
    plot.extra_y_ranges = {"liny": ydr2}

    circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black")
    plot.add_glyph(source, circle, name="mycircle")

    line = Line(x="x", y="y")
    plot.add_glyph(source, line, name="myline")

    rect = Rect(x="x", y="y", width=1, height=1, fill_color="green")
    plot.add_glyph(source, rect, name="myrect")

    plot.add_layout(DatetimeAxis(), 'below')
    plot.add_layout(LogAxis(), 'left')
    plot.add_layout(LinearAxis(y_range_name="liny"), 'left')

    plot.add_layout(Grid(dimension=0), 'left')
    plot.add_layout(Grid(dimension=1), 'left')

    plot.add_tools(
        BoxZoomTool(),
        PanTool(),
        PreviewSaveTool(),
        ResetTool(),
        ResizeTool(),
        WheelZoomTool(),
    )

    return plot
Exemplo n.º 9
0
def make_plot(title, xname, yname):
    plot = Plot(x_range=xdr,
                y_range=ydr,
                data_sources=[lines_source, circles_source],
                title=title,
                width=400,
                height=400,
                border_fill='white',
                background_fill='#e9e0db')
    xaxis = LinearAxis(plot=plot,
                       dimension=0,
                       location="bottom",
                       axis_line_alpha=0)
    yaxis = LinearAxis(plot=plot,
                       dimension=1,
                       location="left",
                       axis_line_alpha=0)
    xgrid = Grid(plot=plot, dimension=0)
    ygrid = Grid(plot=plot, dimension=1)
    line_renderer = GlyphRenderer(
        data_source=lines_source,
        xdata_range=xdr,
        ydata_range=ydr,
        glyph=Line(x='x', y='y', line_color="#666699", line_width=2),
    )
    plot.renderers.append(line_renderer)
    circle_renderer = GlyphRenderer(
        data_source=circles_source,
        xdata_range=xdr,
        ydata_range=ydr,
        glyph=Circle(x=xname,
                     y=yname,
                     radius=6,
                     fill_color="#cc6633",
                     line_color="#cc6633",
                     fill_alpha=0.5),
    )
    plot.renderers.append(circle_renderer)
    return plot, (line_renderer, circle_renderer, xaxis, yaxis, xgrid, ygrid)
Exemplo n.º 10
0
Arquivo: main.py Projeto: mekman/Bokeh
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())
Exemplo n.º 11
0
from bokeh.glyphs import Circle
from bokeh import session

x = arange(-2 * pi, 2 * pi, 0.1)
y = sin(x)

# Create an array of times, starting at the current time, and extending
# for len(x) number of hours.
times = np.arange(len(x)) * 3600000 + time.time()

source = ColumnDataSource(data=dict(x=x, y=y, times=times))

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

circle = Circle(x="times", y="y", fill_color="red", size=5, line_color="black")

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

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = DatetimeAxis(plot=plot, dimension=0, location="min")
yaxis = LinearAxis(plot=plot, dimension=1, location="min")

pantool = PanTool(dataranges=[xdr, ydr], dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dataranges=[xdr, ydr],
                              dimensions=("width", "height"))
Exemplo n.º 12
0
source = ColumnDataSource(
    data=dict(x=x, y=y, z=z, widths=widths, heights=heights))
#source = ObjectArrayDataSource(
#    data = [
#        {'x' : 1, 'y' : 5, 'z':3},
#        {'x' : 2, 'y' : 4, 'z':3, 'radius':10},
#        {'x' : 3, 'y' : 3, 'z':3, 'fill':"blue"},
#        {'x' : 4, 'y' : 2, 'z':3},
#        {'x' : 5, 'y' : 1, 'z':3},
#        ])

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

circle = Circle(x="x", y="y", fill_color="red", radius="z", 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"))

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=80)
xaxis = LinearAxis(plot=plot, dimension=0, location="min")
yaxis = LinearAxis(plot=plot, dimension=1, location="min")
xgrid = Grid(plot=plot, dimension=0)
Exemplo n.º 13
0
 def setUp(self):
     from bokeh.glyphs import Circle
     self.test_circle = Circle()
Exemplo n.º 14
0
y = sin(x)
r = (cos(x)+1) * 6 + 6


source = ColumnDataSource(
    data=dict(
        x=x,
        y=y,
        r=r,
    )
)

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

circle = Circle(x="x", y="y", fill_color="red", radius={"field": "r", "units": "screen"}, line_color="black")

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


pantool = PanTool(dimensions=["width", "height"])
wheelzoomtool = WheelZoomTool(dimensions=["width", "height"])

plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=80)
xaxis = LinearAxis(plot=plot, dimension=0, location="min")
yaxis = LinearAxis(plot=plot, dimension=1, location="min")
Exemplo n.º 15
0
    renderer = Glyph(data_source=source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=glyph)
    plot.renderers.append(renderer)


start_angle = pi + pi / 4
end_angle = -pi / 4

max_kmh = 250
max_mph = max_kmh * 0.621371

major_step, minor_step = 25, 5

add_glyph(Circle(x=0, y=0, radius=1.00, fill_color="white",
                 line_color="black"))
add_glyph(Circle(x=0, y=0, radius=0.05, fill_color="gray", line_color="black"))

add_glyph(
    Text(x=0,
         y=+0.15,
         angle=0,
         text=["km/h"],
         text_color="red",
         text_align="center",
         text_baseline="bottom",
         text_font_style="bold"))
add_glyph(
    Text(x=0,
         y=-0.15,
         angle=0,
Exemplo n.º 16
0
                                        "#2c7fb8", "rgba(120, 230, 150, 0.5)"
                                    ]))

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

circle = Circle(
    x="x",
    y="y",
    size=15,
    # Set the fill color to be dependent on the "color" field of the
    # datasource.  If the field is missing, then the default value is
    # used. Since no explicit default is provided, this picks up the
    # default in FillProps, which is "gray".
    fill_color="color",

    # An alternative form that explicitly sets a default value:
    #fill_color={"default": "red", "field": "color"},

    # Note that line_color is set to a fixed value. This can be any of
    # the SVG named 147 colors, or a hex color string starting with "#",
    # or a string "rgb(r,g,b)" or "rgba(r,g,b,a)".
    # Any other string will be interpreted as a field name to look up
    # on the datasource.
    line_color="black")

glyph_renderer = Glyph(
    data_source=source,
    xdata_range=xdr,
    ydata_range=ydr,
    glyph=circle,
Exemplo n.º 17
0
    data=dict(
        petal_length=flowers['petal_length'],
        petal_width=flowers['petal_width'],
        sepal_length=flowers['sepal_length'],
        sepal_width=flowers['sepal_width'],
        color=flowers['color']
    )
)

xdr = DataRange1d(sources=[source.columns("petal_length")])
ydr = DataRange1d(sources=[source.columns("petal_width")])

plot = Plot(x_range=xdr, y_range=ydr, min_border=80, title="Iris Data")

circle = Circle(
    x="petal_length", y="petal_width", size=10,
    fill_color="color", fill_alpha=0.2, line_color="color"
)
plot.add_glyph(source, circle)

xaxis = LinearAxis(axis_label="petal length", bounds=(1,7), major_tick_in=0)
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis(axis_label="petal width", bounds=(0,2.5), major_tick_in=0)
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

plot.add_tools(PanTool(), WheelZoomTool())

doc = Document()
Exemplo n.º 18
0
map_options = GMapOptions(lat=30.2861, lng=-97.7394, zoom=15)

plot = GMapPlot(x_range=x_range,
                y_range=y_range,
                map_options=map_options,
                title="Austin")
plot.map_options.map_type = "hybrid"

source = ColumnDataSource(data=dict(lat=[30.2861, 30.2855, 30.2869],
                                    lon=[-97.7394, -97.7390, -97.7405],
                                    fill=['orange', 'blue', 'green']))

circle = Circle(x="lon",
                y="lat",
                size=15,
                fill_color="fill",
                line_color="black")
plot.add_glyph(source, circle)

pan = PanTool()
wheel_zoom = WheelZoomTool()
box_select = BoxSelectTool()

plot.add_tools(pan, wheel_zoom, box_select)

overlay = BoxSelectionOverlay(tool=box_select)
plot.add_layout(overlay)

doc = Document()
doc.add(plot)
Exemplo n.º 19
0
    def create(self):
        manufacturers = sorted(mpg["manufacturer"].unique())
        models = sorted(mpg["model"].unique())
        transmissions = sorted(mpg["trans"].unique())
        drives = sorted(mpg["drv"].unique())
        classes = sorted(mpg["class"].unique())

        manufacturer_select = Select(title="Manufacturer:",
                                     value="All",
                                     options=["All"] + manufacturers)
        manufacturer_select.on_change('value', self.on_manufacturer_change)
        model_select = Select(title="Model:",
                              value="All",
                              options=["All"] + models)
        model_select.on_change('value', self.on_model_change)
        transmission_select = Select(title="Transmission:",
                                     value="All",
                                     options=["All"] + transmissions)
        transmission_select.on_change('value', self.on_transmission_change)
        drive_select = Select(title="Drive:",
                              value="All",
                              options=["All"] + drives)
        drive_select.on_change('value', self.on_drive_change)
        class_select = Select(title="Class:",
                              value="All",
                              options=["All"] + classes)
        class_select.on_change('value', self.on_class_change)

        columns = [
            TableColumn(field="manufacturer",
                        header="Manufacturer",
                        type="autocomplete",
                        source=manufacturers),
            TableColumn(field="model",
                        header="Model",
                        type="autocomplete",
                        source=models),
            TableColumn(field="displ",
                        header="Displacement",
                        type="numeric",
                        format="0.00"),
            TableColumn(field="year", header="Year", type="numeric"),
            TableColumn(field="cyl", header="Cylinders", type="numeric"),
            TableColumn(field="trans",
                        header="Transmission",
                        type="dropdown",
                        strict=True,
                        source=transmissions),
            TableColumn(field="drv",
                        header="Drive",
                        type="autocomplete",
                        strict=True,
                        source=drives),
            TableColumn(field="class",
                        header="Class",
                        type="autocomplete",
                        strict=True,
                        source=classes),
            TableColumn(field="cty", header="City MPG", type="numeric"),
            TableColumn(field="hwy", header="Highway MPG", type="numeric"),
        ]
        handson_table = HandsonTable(source=self.source,
                                     columns=columns,
                                     sorting=True)

        xdr = DataRange1d(sources=[self.source.columns("index")])
        #xdr = FactorRange(factors=manufacturers)
        ydr = DataRange1d(
            sources=[self.source.columns("cty"),
                     self.source.columns("hwy")])
        plot = Plot(title=None,
                    data_sources=[self.source],
                    x_range=xdr,
                    y_range=ydr,
                    plot_width=800,
                    plot_height=300)
        xaxis = LinearAxis(plot=plot)
        plot.below.append(xaxis)
        yaxis = LinearAxis(plot=plot)
        ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
        plot.left.append(yaxis)
        cty = Glyph(data_source=self.source,
                    glyph=Circle(x="index",
                                 y="cty",
                                 fill_color="#396285",
                                 size=8,
                                 fill_alpha=0.5,
                                 line_alpha=0.5))
        hwy = Glyph(data_source=self.source,
                    glyph=Circle(x="index",
                                 y="hwy",
                                 fill_color="#CE603D",
                                 size=8,
                                 fill_alpha=0.5,
                                 line_alpha=0.5))
        select_tool = BoxSelectTool(renderers=[cty, hwy], select_y=False)
        plot.tools.append(select_tool)
        overlay = BoxSelectionOverlay(tool=select_tool)
        plot.renderers.extend([cty, hwy, ygrid, overlay])

        controls = VBox(children=[
            manufacturer_select, model_select, transmission_select,
            drive_select, class_select
        ],
                        width=200)
        top_panel = HBox(children=[controls, plot])
        layout = VBox(children=[top_panel, handson_table])

        return layout
Exemplo n.º 20
0
colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}

flowers['color'] = flowers['species'].map(lambda x: colormap[x])

source = ColumnDataSource(data=dict(petal_length=flowers['petal_length'],
                                    petal_width=flowers['petal_width'],
                                    sepal_length=flowers['sepal_length'],
                                    sepal_width=flowers['sepal_width'],
                                    color=flowers['color']))

xdr = DataRange1d(sources=[source.columns("petal_length")])
ydr = DataRange1d(sources=[source.columns("petal_width")])

circle = Circle(x="petal_length",
                y="petal_width",
                fill_color="color",
                fill_alpha=0.2,
                radius=5,
                line_color="color")

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

plot = Plot(x_range=xdr,
            y_range=ydr,
            data_sources=[source],
            border=80,
            title="Iris Data")
Exemplo n.º 21
0
             line_color="#F4A582",
             line_width=3)),
    ("wedge",
     Wedge(x="x",
           y="y",
           radius=screen(15),
           start_angle=0.6,
           end_angle=4.1,
           fill_color="#B3DE69")),
]

markers = [
    ("circle",
     Circle(x="x",
            y="y",
            radius=0.1,
            radius_units="data",
            fill_color="#3288BD")),
    ("circle_x",
     CircleX(x="x", y="y", size="sizes", line_color="#DD1C77",
             fill_color=None)),
    ("circle_cross",
     CircleCross(x="x",
                 y="y",
                 size="sizes",
                 line_color="#FB8072",
                 fill_color=None,
                 line_width=2)),
    ("square", Square(x="x", y="y", size="sizes", fill_color="#74ADD1")),
    ("square_x",
     SquareX(x="x",
Exemplo n.º 22
0
)
from bokeh.resources import INLINE

x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
y2 = linspace(0, 100, len(y))

source = ColumnDataSource(
    data=dict(x=x, y=y, y2=y2)
)

plot = Plot(x_range=Range1d(start=-6.5, end=6.5), y_range=Range1d(start=-1.1, end=1.1), min_border=80)

plot.extra_y_ranges = {"foo": Range1d(start=0, end=100)}

circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black")
plot.add_glyph(source, circle)

plot.add_layout(LinearAxis(), 'below')
plot.add_layout(LinearAxis(), 'left')


circle2 = Circle(x="x", y="y2", fill_color="blue", size=5, line_color="black")
plot.add_glyph(source, circle2, y_range_name="foo")

plot.add_layout(LinearAxis(y_range_name="foo"), 'left')

plot.add_tools(PanTool(), WheelZoomTool())

doc = Document()
doc.add(plot)
Exemplo n.º 23
0
ygrid = Grid(plot=plot, dimension=1)
pantool = PanTool(plot=plot)
wheelzoomtool = WheelZoomTool(plot=plot)
plot.tools.extend([pantool, wheelzoomtool])

# Plot some data on top
source = ColumnDataSource(data=dict(lat=[30.2861, 30.2855, 30.2869],
                                    lon=[-97.7394, -97.7390, -97.7405],
                                    fill=['orange', 'blue', 'green']))

circle_renderer = Glyph(data_source=source,
                        xdata_range=x_range,
                        ydata_range=y_range,
                        glyph=Circle(x="lon",
                                     y="lat",
                                     fill_color="fill",
                                     size=15,
                                     radius_units="screen",
                                     line_color="black"))
plot.data_sources.append(source)
plot.renderers.append(circle_renderer)

try:
    sess = session.PlotServerSession(serverloc="http://localhost:5006",
                                     username="******",
                                     userapikey="nokey")
except requests.exceptions.ConnectionError:
    print(
        "ERROR: This example requires the plot server. Please make sure plot server is running, by executing 'bokeh-server'"
    )
    sys.exit(1)
Exemplo n.º 24
0
session.use_doc('glyph2_server')
session.load_document(document)

x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
r = (cos(x)+1) * 6 + 6

source = ColumnDataSource(data=dict(x=x, y=y, r=r))

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

plot = Plot(x_range=xdr, y_range=ydr, min_border=80)

circle = Circle(
    x="x", y="y", size="r",
    fill_color="red", line_color="black"
)
plot.add_glyph(source, circle)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

plot.add_tools(PanTool(), WheelZoomTool())

document.add(plot)
Exemplo n.º 25
0
def make_plot():

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

    from bokeh.objects import (Plot, DataRange1d, LinearAxis, ColumnDataSource,
                               GlyphRenderer, PanTool, 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"])
    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)

    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()
    return plot