Пример #1
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
Пример #2
0
    def map(self,
            latitude=35.349,
            longitude=-116.595,
            zoom=17,
            load=True,
            title="Map"):
        if load:
            self.load_all()
        x_range = Range1d()
        y_range = Range1d()
        plot = GMapPlot(x_range=x_range,
                        y_range=y_range,
                        center_lat=latitude,
                        center_lng=longitude,
                        zoom_level=zoom,
                        data_sources=[],
                        canvas_width=600,
                        canvas_height=600,
                        outer_width=600,
                        outer_height=600,
                        title=title)

        select_tool = BoxSelectTool()
        overlay = BoxSelectionOverlay(tool=select_tool)
        plot.renderers.append(overlay)
        plot.tools.append(select_tool)

        xgrid = Grid(plot=plot, dimension=0)
        ygrid = Grid(plot=plot, dimension=1)
        pantool = PanTool(plot=plot)
        zoomtool = ZoomTool(plot=plot)
        plot.tools.extend([pantool, zoomtool])
        self.add(plot, xgrid, ygrid, pantool, zoomtool, x_range, y_range,
                 select_tool, overlay)
        self.cdx.plotlist.children.insert(0, plot)
        self.cdx.activeplot = plot
        self.cdx.plotlist._dirty = True
        stored = self.store_all()
        # print stored
        return stored
Пример #3
0
x_range = Range1d()
y_range = Range1d()
plot = GMapPlot(x_range=x_range,
                y_range=y_range,
                center_lat=30.2861,
                center_lng=-97.7394,
                zoom_level=15,
                data_sources=[],
                canvas_width=600,
                canvas_height=600,
                outer_width=600,
                outer_height=600,
                title="Austin")

select_tool = SelectionTool()
overlay = BoxSelectionOverlay(tool=select_tool)
plot.renderers.append(overlay)
plot.tools.append(select_tool)

xgrid = Grid(plot=plot, dimension=0)
ygrid = Grid(plot=plot, dimension=1)
pantool = PanTool(plot=plot)
zoomtool = ZoomTool(plot=plot)
plot.tools.extend([pantool, zoomtool])

sess = session.PlotServerSession(username="******",
                                 serverloc="http://localhost:5006",
                                 userapikey="nokey")

sess.use_doc("maps")
sess.add(plot, xgrid, ygrid, pantool, zoomtool, x_range, y_range, select_tool,
Пример #4
0
source = ColumnDataSource()
source.add(x, name='x')
source.add(y, name='y')
source.add(2 * y, name='2y')
source.add(3 * y, name='3y')

hold()
scatter('x', 'y', source=source, tools="pan,zoom,resize")
scatter('x', '2y', source=source, tools="pan,zoom,resize")
scatter('x', '3y', source=source, color="green", tools="pan,zoom,resize")

plot = curplot()

tool = DataRangeBoxSelectionTool(plot=plot)
overlay = BoxSelectionOverlay(tool=tool)
plot.renderers.append(overlay)
plot.tools.append(tool)
plot._dirty = True
sess = plotting._config["session"]
sess.load_all_callbacks()

sess.add(tool)
sess.add(overlay)
tool.on_change("xselect", plot, "dummy")
tool.on_change("yselect", plot, "dummy")

sess.store_all()
sess.store_all_callbacks()

#execute this yourself, you should see the dummy callback fire if anything has changed
Пример #5
0
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)

if __name__ == "__main__":
    filename = "maps.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Google Maps Example"))
    print("Wrote %s" % filename)
    view(filename)
Пример #6
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