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") ydr.tags.append(11) 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(), SaveTool(), ResetTool(), ResizeTool(), WheelZoomTool(), ) return plot
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") ydr.tags.append(11) 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(), SaveTool(), ResetTool(), WheelZoomTool(), ) return plot
PanTool, Plot, Range1d, WheelZoomTool,) from bokeh.resources import INLINE from bokeh.util.browser import view 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_x_ranges = {"qux": Range1d(start=100, end=0)} plot.extra_y_ranges = {"foo": Range1d(start=0, end=100)} plot.add_layout(LinearAxis(axis_label="default range"), 'above') plot.add_layout(LinearAxis(axis_label="qux range", x_range_name="qux"), 'above') plot.add_layout(LinearAxis(axis_label="default range"), 'below') plot.add_layout(LinearAxis(axis_label="qux range", x_range_name="qux"), 'below') plot.add_layout(LinearAxis(axis_label="default range"), 'left') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'left') plot.add_layout(LinearAxis(axis_label="default range"), 'right') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'right') circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black") plot.add_glyph(source, circle)
Plot, LinearAxis, ColumnDataSource, Range1d, PanTool, WheelZoomTool ) 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_x_ranges = {"qux": Range1d(start=100, end=0)} plot.extra_y_ranges = {"foo": Range1d(start=0, end=100)} plot.add_layout(LinearAxis(axis_label="default range"), 'above') plot.add_layout(LinearAxis(axis_label="qux range", x_range_name="qux"), 'above') plot.add_layout(LinearAxis(axis_label="default range"), 'below') plot.add_layout(LinearAxis(axis_label="qux range", x_range_name="qux"), 'below') plot.add_layout(LinearAxis(axis_label="default range"), 'left') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'left') plot.add_layout(LinearAxis(axis_label="default range"), 'right') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'right') circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black") plot.add_glyph(source, circle)
def create_plot_figure(self, active_tab): """ create a new plot and insert it in given tab. """ #find table name of active tab and its bokeh instances test = active_tab.name#contains csv filename x_sel=active_tab.select_one({'name':'x_sel'}) y_sel=active_tab.select_one({'name':'y_sel'}) y_sel2=active_tab.select_one({'name':'y_sel2'}) plot_df = self.plot_dfs[test] source = ColumnDataSource(plot_df) #Replace entirely p with a new plot p = Plot( x_range=DataRange1d(), y_range=DataRange1d(), plot_height=600, plot_width=600, title=Title(text=self.sel_csv), name='plot') p.add_tools(BoxZoomTool(), SaveTool(), ResetTool(), PanTool(), HoverTool(tooltips=[('x','$x'), ('y','$y')])) #see https://bokeh.github.io/blog/2017/7/5/idiomatic_bokeh/ x_axis = LinearAxis( axis_label = x_sel.value, ticker=BasicTicker(desired_num_ticks =10), name='x_axis') y_axis = LinearAxis( axis_label = y_sel.value, ticker=BasicTicker(desired_num_ticks =10), name='y_axis') #primary y-axis ly = p.add_glyph(source, Line(x=x_sel.value, y=y_sel.value, line_width=2, line_color='black'), name = 'ly' ) p.add_layout(x_axis,'below') p.add_layout(y_axis,'left') p.y_range.renderers = [ly] #secondary y-axis if y_sel2.value.strip() != 'None':#secondary y-axis y_axis2 = LinearAxis( axis_label = y_sel2.value, ticker=BasicTicker(desired_num_ticks=10), name='y_axis2', y_range_name='right_axis') p.add_layout(y_axis2,'right') p.extra_y_ranges = {"right_axis": DataRange1d()} ly2 = p.add_glyph(source, Line(x=x_sel.value, y=y_sel2.value, line_width=2, line_color='red'), y_range_name='right_axis', name = 'ly2' ) p.extra_y_ranges['right_axis'].renderers = [ly2] leg_items = [LegendItem(label=y_sel.value, renderers=[ly]), LegendItem(label=y_sel2.value, renderers=[ly2])] else: leg_items = [LegendItem(label=y_sel.value, renderers=[ly])] p.add_layout(Legend(items=leg_items, location='top_right') ) active_tab.child.children[1] = p return p