Exemplo n.º 1
0
class TestCircle(unittest.TestCase):

    def setUp(self):
        from bokeh.glyphs import Circle
        self.test_circle = Circle()

    def test_expected_properties(self):
        expected_properties = set(['radius'])
        actual_properties = get_prop_set(type(self.test_circle))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_circle.radius, {'default': 4, 'field': None})
        self.assertEqual(self.test_circle.__view_model__, 'circle')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected['type'] = 'circle'
        expected['size'] = {'default': 4, 'field': None, 'units': 'screen'}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
        # self.test_circle.size = 6
        # expected['size'] = {'value': 6, 'units': 'screen'}
        # self.assertEqual(self.test_circle.to_glyphspec(), expected)
        self.test_circle.radius = 500
        del expected['size']
        expected['radius'] = {'units': 'data', 'value': 500}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
Exemplo n.º 2
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Circle
        self.test_circle = Circle()

    def test_expected_properties(self):
        expected_properties = set(['radius'])
        actual_properties = get_prop_set(type(self.test_circle))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_circle.radius, {
            'default': 4,
            'field': None
        })
        self.assertEqual(self.test_circle.__view_model__, 'circle')

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected['type'] = 'circle'
        expected['size'] = {'default': 4, 'field': None, 'units': 'screen'}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
        # self.test_circle.size = 6
        # expected['size'] = {'value': 6, 'units': 'screen'}
        # self.assertEqual(self.test_circle.to_glyphspec(), expected)
        self.test_circle.radius = 500
        del expected['size']
        expected['radius'] = {'units': 'data', 'value': 500}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
Exemplo n.º 3
0
class TestCircle(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Circle

        self.test_circle = Circle()

    def test_expected_properties(self):
        expected_properties = set(["radius"])
        actual_properties = get_prop_set(type(self.test_circle))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_circle.radius, {"default": 4, "field": None})
        self.assertEqual(self.test_circle.__view_model__, "circle")

    def test_to_glyphspec(self):
        expected = dict(GENERIC_GLYPH_DICT)
        expected["type"] = "circle"
        expected["size"] = {"default": 4, "field": None, "units": "screen"}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
        # self.test_circle.size = 6
        # expected['size'] = {'value': 6, 'units': 'screen'}
        # self.assertEqual(self.test_circle.to_glyphspec(), expected)
        self.test_circle.radius = 500
        del expected["size"]
        expected["radius"] = {"units": "data", "value": 500}
        self.assertEqual(self.test_circle.to_glyphspec(), expected)
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
class TestCircle(unittest.TestCase):
    def setUp(self):
        from bokeh.glyphs import Circle
        self.test_circle = Circle()

    def test_expected_properties(self):        
        expected_properties = set(['radius'])
        actual_properties = get_prop_set(type(self.test_circle))
        self.assertTrue(expected_properties.issubset(actual_properties))

    def test_expected_values(self):
        self.assertEqual(self.test_circle.radius , {'default':4,'field':None})
        self.assertEqual(self.test_circle.__view_model__,'circle')

    def test_to_glyphspec(self):
        self.assertEqual(self.test_circle.to_glyphspec(), {'line_color': {'value': 'black'}, 'fill_color': {'value': 'gray'}, 'radius': {'units': 'screen', 'field': None, 'default': 4}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'type': 'circle', 'size': {'units': 'screen', 'field': None, 'default': 4}})
        self.test_circle.radius = 500
        self.assertEqual(self.test_circle.to_glyphspec(), {'line_color': {'value': 'black'}, 'fill_color': {'value': 'gray'}, 'radius': {'units': 'screen', 'value': 500}, 'y': {'units': 'data', 'field': 'y'}, 'x': {'units': 'data', 'field': 'x'}, 'type': 'circle', 'size': {'units': 'screen', 'field': None, 'default': 4}})
Exemplo n.º 6
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.º 7
0
 def setUp(self):
     from bokeh.glyphs import Circle
     self.test_circle = Circle()
Exemplo n.º 8
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.º 9
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
Exemplo n.º 10
0
 def setUp(self):
     from bokeh.glyphs import Circle
     self.test_circle = Circle()
Exemplo n.º 11
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")