Пример #1
0
class TestLine(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Line
        self.test_line = Line()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y'])
        actual_properties = get_prop_set(type(self.test_line))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_line.x, 'x')
        self.assertEqual(self.test_line.y, 'y')
        self.assertEqual(self.test_line.__view_model__, 'line')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_XY_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected['type'] = 'line'
        self.assertEqual(self.test_line.to_glyphspec(), expected)
        self.test_line.x = [50]
        self.test_line.y = [51]
        expected.update({
            'x':  {'units': 'data', 'value': [50]},
            'y':  {'units': 'data', 'value': [51]},
        })
        self.assertEqual(self.test_line.to_glyphspec(), expected)
Пример #2
0
class TestLine(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Line

        self.test_line = Line()

    def test_expected_properties(self):
        expected_properties = set(["x", "y"])
        actual_properties = get_prop_set(type(self.test_line))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_line.x, "x")
        self.assertEqual(self.test_line.y, "y")
        self.assertEqual(self.test_line.__view_model__, "line")

    def test_to_glyphspec(self):
        expected = dict(GENERIC_XY_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected["type"] = "line"
        self.assertEqual(self.test_line.to_glyphspec(), expected)
        self.test_line.x = [50]
        self.test_line.y = [51]
        expected.update({"x": {"units": "data", "value": [50]}, "y": {"units": "data", "value": [51]}})
        self.assertEqual(self.test_line.to_glyphspec(), expected)
Пример #3
0
class TestLine(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Line
        self.test_line = Line()

    def test_expected_properties(self):
        expected_properties = set(['x', 'y'])
        actual_properties = get_prop_set(type(self.test_line))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_line.x, 'x')
        self.assertEqual(self.test_line.y, 'y')
        self.assertEqual(self.test_line.__view_model__, 'line')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_XY_DICT)
        expected.update(GENERIC_LINE_DICT)
        expected['type'] = 'line'
        self.assertEqual(self.test_line.to_glyphspec(), expected)
        self.test_line.x = [50]
        self.test_line.y = [51]
        expected.update({
            'x': {
                'units': 'data',
                'value': [50]
            },
            'y': {
                'units': 'data',
                'value': [51]
            },
        })
        self.assertEqual(self.test_line.to_glyphspec(), expected)
Пример #4
0
def population():
    xdr = FactorRange(factors=years)
    ydr = DataRange1d(
        sources=[source_known.columns("y"),
                 source_predicted.columns("y")])

    plot = Plot(title=None,
                x_range=xdr,
                y_range=ydr,
                plot_width=800,
                plot_height=200)

    plot.add_layout(CategoricalAxis(major_label_orientation=pi / 4), 'below')

    line_known = Line(x="x", y="y", line_color="violet", line_width=2)
    line_known_glyph = plot.add_glyph(source_known, line_known)

    line_predicted = Line(x="x",
                          y="y",
                          line_color="violet",
                          line_width=2,
                          line_dash="dashed")
    line_predicted_glyph = plot.add_glyph(source_predicted, line_predicted)

    plot.add_layout(
        Legend(orientation="bottom_right",
               legends=dict(known=[line_known_glyph],
                            predicted=[line_predicted_glyph])))

    return plot
Пример #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
Пример #6
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
Пример #7
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
Пример #8
0
def trail_map(data):
    lon = (min(data.lon) + max(data.lon))/2
    lat = (min(data.lat) + max(data.lat))/2

    map_options = GMapOptions(lng=lon, lat=lat, zoom=13)
    plot = GMapPlot(title="%s - Trail Map" % title, map_options=map_options, plot_width=800, plot_height=800)

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

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

    xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker, grid_line_dash="dashed", grid_line_color="gray")
    ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker, grid_line_dash="dashed", grid_line_color="gray")
    plot.renderers.extend([xgrid, ygrid])

    hover = HoverTool(tooltips=dict(distance="@dist"))
    plot.add_tools(hover, PanTool(), WheelZoomTool(), ResetTool(), BoxSelectTool())

    line_source = ColumnDataSource(dict(x=data.lon, y=data.lat, dist=data.dist))

    line = Line(x="x", y="y", line_color="blue", line_width=2)
    plot.add_glyph(line_source, line)

    plot.x_range = DataRange1d(sources=[line_source.columns("x")])
    plot.y_range = DataRange1d(sources=[line_source.columns("y")])

    return plot
Пример #9
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
def line_advanced():

    source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths,
                heights=heights))
    
    xdr = DataRange1d(sources=[source.columns("x")])
    xdr2 = DataRange1d(sources=[source.columns("x")])
    ydr = DataRange1d(sources=[source.columns("y")])
    ydr2 = DataRange1d(sources=[source.columns("y")])
    
    line_glyph = Line(x="x", y="y", line_color="blue")
    
    renderer = GlyphRenderer(data_source = source,  xdata_range = xdr,
            ydata_range = ydr, glyph = line_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=50)
    plot.tools = [pantool, zoomtool]
    plot.renderers.append(renderer)
    
    #notice that these two have a differen y data range
    renderer2 = GlyphRenderer(data_source = source, xdata_range = xdr,
            ydata_range = ydr2, glyph = line_glyph)
    
    plot2 = Plot(x_range=xdr, y_range=ydr2, data_sources=[source], 
            border=50)
    
    plot2.renderers.append(renderer2)
    
    #notice that these two have a differen y data range
    renderer3 = GlyphRenderer(data_source = source, xdata_range = xdr2,
            ydata_range = ydr, glyph = line_glyph)
    
    plot3 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], 
            border=50)
    
    plot3.renderers.append(renderer3)
    
    #this is a dummy plot with no renderers
    plot4 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], 
            border=50)
    
    
    sess = session.HTMLFileSession("line_linked_advanced.html")
    sess.add(plot, renderer, source, xdr, ydr, pantool, zoomtool)
    
    sess.add(plot2, renderer2, ydr2, xdr2, renderer3, plot3, plot4)
    grid = GridPlot(children=[[plot, plot2], [plot3, plot4 ]], name="linked_advanced")
    
    sess.add(grid)
    sess.plotcontext.children.append(grid)
    
    
    sess.save(js="relative", css="relative", rootdir=os.path.abspath("."))
    print "Wrote line_linked_advanced.html"
    
        webbrowser.open("file://" + os.path.abspath("line_linked_advanced.html"))
Пример #11
0
class TestLine(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Line
        self.test_line = Line()

    def test_expected_properties(self):
        expected_properties = set(['x','y'])
        actual_properties = get_prop_set(type(self.test_line))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_line.x,'x')
        self.assertEqual(self.test_line.y,'y')
        self.assertEqual(self.test_line.__view_model__,'line')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_line.to_glyphspec(), {'line_color': {'value': 'black'}, 'y': {'units': 'data', 'field': 'y'}, 'type': 'line', 'x': {'units': 'data', 'field': 'x'}})
        self.test_line.x = 50
        self.test_line.y = 51
        self.assertEqual(self.test_line.to_glyphspec(), {'y': {'units': 'data', 'value': 51}, 'x': {'units': 'data', 'value': 50}, 'type': 'line', 'line_color': {'value': 'black'}})
Пример #12
0
def population():
    xdr = FactorRange(factors=years)
    ydr = DataRange1d(sources=[source_known.columns("y"), source_predicted.columns("y")])

    plot = Plot(title=None, data_sources=[source_known, source_predicted], x_range=xdr, y_range=ydr, plot_width=800, plot_height=200)

    xaxis = CategoricalAxis(plot=plot, dimension=0, major_label_orientation=pi/4)
    # yaxis = LinearAxis(plot=plot, dimension=1, ...)

    line_known = Line(x="x", y="y", line_color="violet", line_width=2)
    line_known_glyph = Glyph(data_source=source_known, xdata_range=xdr, ydata_range=ydr, glyph=line_known)
    plot.renderers.append(line_known_glyph)

    line_predicted = Line(x="x", y="y", line_color="violet", line_width=2, line_dash="dashed")
    line_predicted_glyph = Glyph(data_source=source_predicted, xdata_range=xdr, ydata_range=ydr, glyph=line_predicted)
    plot.renderers.append(line_predicted_glyph)

    legend = Legend(plot=plot, orientation="bottom_right", legends=dict(known=[line_known_glyph], predicted=[line_predicted_glyph]))
    plot.renderers.append(legend)

    return plot
Пример #13
0
def large_plot(n):
    from bokeh.objects import (Plot, PlotContext, LinearAxis, Grid, Glyph,
                               ColumnDataSource, DataRange1d, PanTool,
                               WheelZoomTool, BoxZoomTool, BoxSelectTool,
                               BoxSelectionOverlay, ResizeTool,
                               PreviewSaveTool, ResetTool)
    from bokeh.glyphs import Line

    context = PlotContext()
    objects = set([context])

    for i in xrange(n):
        source = ColumnDataSource(data=dict(x=[0, i + 1], y=[0, i + 1]))
        xdr = DataRange1d(sources=[source.columns("x")])
        ydr = DataRange1d(sources=[source.columns("y")])
        plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source])
        xaxis = LinearAxis(plot=plot, dimension=0)
        yaxis = LinearAxis(plot=plot, dimension=1)
        xgrid = Grid(plot=plot, dimension=0)
        ygrid = Grid(plot=plot, dimension=1)
        tickers = [
            xaxis.ticker, xaxis.formatter, yaxis.ticker, yaxis.formatter
        ]
        renderer = Glyph(data_source=source,
                         xdata_range=xdr,
                         ydata_range=ydr,
                         glyph=Line(x='x', y='y'))
        plot.renderers.append(renderer)
        pan = PanTool(plot=plot)
        wheel_zoom = WheelZoomTool(plot=plot)
        box_zoom = BoxZoomTool(plot=plot)
        box_select = BoxSelectTool(plot=plot)
        box_selection = BoxSelectionOverlay(tool=box_select)
        resize = ResizeTool(plot=plot)
        previewsave = PreviewSaveTool(plot=plot)
        reset = ResetTool(plot=plot)
        tools = [
            pan, wheel_zoom, box_zoom, box_select, box_selection, resize,
            previewsave, reset
        ]
        plot.tools.append(tools)
        context.children.append(plot)
        objects |= set(
            [source, xdr, ydr, plot, xaxis, yaxis, xgrid, ygrid, renderer] +
            tickers + tools)

    return context, objects
Пример #14
0
def make_plot(source, xname, yname, line_color, xdr=None, ydr=None):
    """ Returns a tuple (plot, [obj1...objN]); the former can be added
    to a GridPlot, and the latter is added to the plotcontext.
    """
    if xdr is None:
        xdr = DataRange1d(sources=[source.columns(xname)])
    if ydr is None:
        ydr = DataRange1d(sources=[source.columns(yname)])

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

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

    plot.add_glyph(source, Line(x=xname, y=yname, line_color=line_color))

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

    return plot
Пример #15
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
Пример #16
0
def altitude_profile(data):
    plot = Plot(title="%s - Altitude Profile" % title,
                plot_width=800,
                plot_height=400)

    xaxis = LinearAxis(axis_label="Distance (km)")
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis(axis_label="Altitude (m)")
    plot.add_layout(yaxis, 'left')

    xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker)
    ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
    plot.renderers.extend([xgrid, ygrid])

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

    X, Y = data.dist, data.alt
    y0 = min(Y)

    patches_source = ColumnDataSource(
        dict(xs=[[X[i], X[i + 1], X[i + 1], X[i]] for i in range(len(X[:-1]))],
             ys=[[y0, y0, Y[i + 1], Y[i]] for i in range(len(Y[:-1]))],
             color=data.colors[:-1]))

    patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color")
    plot.add_glyph(patches_source, patches)

    line_source = ColumnDataSource(dict(
        x=data.dist,
        y=data.alt,
    ))

    line = Line(x='x', y='y', line_color="black", line_width=1)
    plot.add_glyph(line_source, line)

    plot.x_range = DataRange1d(sources=[line_source.columns("x")])
    plot.y_range = DataRange1d(sources=[line_source.columns("y")])

    return plot
Пример #17
0
def make_plot(source, xname, yname, line_color, xdr=None, ydr=None):
    """ Returns a tuple (plot, [obj1...objN]); the former can be added
    to a GridPlot, and the latter is added to the plotcontext.
    """
    if xdr is None:
        xdr = DataRange1d(sources=[source.columns(xname)])
    if ydr is None:
        ydr = DataRange1d(sources=[source.columns(yname)])
    plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=50)
    xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
    yaxis = LinearAxis(plot=plot, dimension=1, location="left")
    pantool = PanTool(dimensions=["width", "height"])
    wheelzoomtool = WheelZoomTool(dimensions=["width", "height"])
    renderer = Glyph(
        data_source=source,
        xdata_range=xdr,
        ydata_range=ydr,
        glyph=Line(x=xname, y=yname, line_color=line_color),
    )
    plot.renderers.append(renderer)
    plot.tools = [pantool, wheelzoomtool]
    return plot
Пример #18
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)
Пример #19
0
def test_Line():
    glyph = Line()
    assert glyph.x == "x"
    assert glyph.y == "y"
    yield check_line, glyph
    yield check_props, glyph, ["x", "y"], LINE
Пример #20
0
 def setUp(self):
     from bokeh.glyphs import Line
     self.test_line = Line()
Пример #21
0
        "taylor(%s)" % expr: [line_t_glyph],
    }
    source.data = dict(x=x, fy=fy, ty=ty)
    slider.value = order

    session.store_document(document)


source = ColumnDataSource(data=dict(x=[], fy=[], ty=[]))

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

plot = Plot(x_range=xdr, y_range=ydr, plot_width=800, plot_height=400)

line_f = Line(x="x", y="fy", line_color="blue", line_width=2)
line_f_glyph = plot.add_glyph(source, line_f)
plot.add_layout(line_f_glyph)

line_t = Line(x="x", y="ty", line_color="red", line_width=2)
line_t_glyph = plot.add_glyph(source, line_t)
plot.add_layout(line_t_glyph)

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

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

xgrid = Grid(dimension=0, ticker=xaxis.ticker)
ygrid = Grid(dimension=1, ticker=yaxis.ticker)
Пример #22
0
patch1 = Patch(x="dates", y="times", fill_color="skyblue", fill_alpha=0.8)
patch1_glyph = Glyph(data_source=patch1_source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=patch1)
plot.renderers.append(patch1_glyph)

patch2 = Patch(x="dates", y="times", fill_color="orange", fill_alpha=0.8)
patch2_glyph = Glyph(data_source=patch2_source,
                     xdata_range=xdr,
                     ydata_range=ydr,
                     glyph=patch2)
plot.renderers.append(patch2_glyph)

line1 = Line(x="dates", y="sunrises", line_color="yellow", line_width=2)
line1_glyph = Glyph(data_source=source,
                    xdata_range=xdr,
                    ydata_range=ydr,
                    glyph=line1)
plot.renderers.append(line1_glyph)

line2 = Line(x="dates", y="sunsets", line_color="red", line_width=2)
line2_glyph = Glyph(data_source=source,
                    xdata_range=xdr,
                    ydata_range=ydr,
                    glyph=line2)
plot.renderers.append(line2_glyph)

text = Text(x="dates", y="times", text="texts", angle=0, text_align="center")
text_glyph = Glyph(data_source=text_source,
Пример #23
0
      start_angle=0.6,
      end_angle=4.1,
      line_color="#BEAED4",
      line_width=3)),
 ("bezier",
  Bezier(x0="x",
         y0="y",
         x1="xp02",
         y1="y",
         cx0="xp01",
         cy0="yp01",
         cx1="xm01",
         cy1="ym01",
         line_color="#D95F02",
         line_width=2)),
 ("line", Line(x="x", y="y", line_color="#F46D43")),
 ("multi_line",
  MultiLine(xs="xs", ys="ys", line_color="#8073AC", line_width=2)),
 ("oval",
  Oval(x="x",
       y="y",
       width=screen(15),
       height=screen(25),
       angle=-0.7,
       fill_color="#1D91C0")),
 ("patch", Patch(x="x", y="y", fill_color="#A6CEE3")),
 ("patches", Patches(xs="xs", ys="ys", fill_color="#FB9A99")),
 ("quad",
  Quad(left="x", right="xm01", top="y", bottom="ym01",
       fill_color="#B3DE69")),
 ("quadratic",
Пример #24
0
from bokeh.objects import (Plot, DataRange1d, LinearAxis, ColumnDataSource,
                           PanTool, WheelZoomTool, PreviewSaveTool)
from bokeh.resources import INLINE

x = np.linspace(-2 * pi, 2 * pi, 1000)
y = sin(x)
z = cos(x)

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

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

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

line_glyph = Line(x="x", y="y", line_color="blue")
plot.add_glyph(source, line_glyph)

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

pan = PanTool()
wheel_zoom = WheelZoomTool()
preview_save = PreviewSaveTool()

plot.add_tools(pan, wheel_zoom, preview_save)

doc = Document()
doc.add(plot)

if __name__ == "__main__":
Пример #25
0
session = session.Session()
session.use_doc('line_animate')
session.load_document(document)

x = np.linspace(-2 * pi, 2 * pi, 1000)
x_static = np.linspace(-2 * pi, 2 * pi, 1000)
y = sin(x)
z = cos(x)

source = ColumnDataSource(data=dict(x=x, y=y, z=z, x_static=x_static))

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

line_glyph = Line(x="x", y="y", line_color="blue")
line_glyph2 = Line(x="x", y="z", line_color="red")
renderer = Glyph(data_source=source,
                 xdata_range=xdr,
                 ydata_range=ydr,
                 glyph=line_glyph)
renderer2 = Glyph(data_source=source,
                  xdata_range=xdr_static,
                  ydata_range=ydr,
                  glyph=line_glyph2)

plot = Plot(x_range=xdr_static,
            y_range=ydr,
            data_sources=[source],
            min_border=50)
xaxis = LinearAxis(plot=plot, dimension=0, location="bottom")
Пример #26
0
from bokeh.glyphs import Line
from bokeh import session

# The Line glyph needs arrays of arrays of X and Y, so use newaxis.
x = arange(-2 * pi, 2 * pi, 0.1)
y = sin(x)

source = ColumnDataSource(data=dict(xs=[x], ys=[y]))

#xdr = DataRange1d(sources=[source.columns("xs")])
#ydr = DataRange1d(sources=[source.columns("ys")])

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)
Пример #27
0
from bokeh.glyphs import Line
from bokeh import session

# The Line glyph needs arrays of arrays of X and Y, so use newaxis.
x = arange(-2 * pi, 2 * pi, 0.1)
y = sin(x)

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

#xdr = DataRange1d(sources=[source.columns("xs")])
#ydr = DataRange1d(sources=[source.columns("ys")])

xdr = Range1d(start=-2 * pi, end=2 * pi)
ydr = Range1d(start=-1, end=1)

line = Line(x="x", y="y", line_color="blue", line_width=2)
glyph_renderer = Glyph(data_source=source,
                       xdata_range=xdr,
                       ydata_range=ydr,
                       glyph=line)

pantool = PanTool(dataranges=[xdr, ydr], dimensions=("width", "height"))
wheelzoomtool = WheelZoomTool(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 = Grid(plot=plot, dimension=0)
ygrid = Grid(plot=plot, dimension=1)
Пример #28
0
 def setUp(self):
     from bokeh.glyphs import Line
     self.test_line = Line()