def plot_bokeh_history(solvers, x, y, x_arrays, y_arrays, mins, legends, log_scale, show): import bokeh.plotting as bk min_x, max_x, min_y, max_y = mins if log_scale: # Bokeh has a weird behaviour when using logscale with 0 entries... # We use the difference between smallest value of second small # to set the range of y all_ys = np.hstack(y_arrays) y_range_min = np.min(all_ys[all_ys != 0]) if y_range_min < 0: raise ValueError("Cannot plot negative values on a log scale") fig = bk.Figure(plot_height=300, y_axis_type="log", y_range=[y_range_min, max_y]) else: fig = bk.Figure(plot_height=300, x_range=[min_x, max_x], y_range=[min_y, max_y]) for i, (solver, x_array, y_array, legend) in enumerate(zip(solvers, x_arrays, y_arrays, legends)): color = get_plot_color(i) fig.line(x_array, y_array, line_width=3, legend=legend, color=color) fig.xaxis.axis_label = x fig.yaxis.axis_label = y fig.xaxis.axis_label_text_font_size = "12pt" fig.yaxis.axis_label_text_font_size = "12pt" if show: bk.show(fig) return None else: return fig
def initialize(): for scenario_name in scenarios: #build plots plot = { 'figure': bp.Figure(toolbar_location='right', tools='save,pan,box_zoom,reset', width=250, height=225), 'series': [], 'xmin': 0, 'xmax': 0, 'ymin': 0, 'ymax': 0, } plot['figure'].title.text = scenario_name plot['figure'].xaxis.major_label_orientation = 'vertical' plot['figure'].xaxis.major_label_standoff = 25 plot_list['scenarios'][scenario_name] = plot #build maps map_plot = bm.Plot(x_range=bm.DataRange1d(), y_range=bm.DataRange1d(), plot_width=450, plot_height=250, toolbar_location=None) map_plot.title.text = scenario_name map_list[scenario_name]['plot'] = map_plot combined_plot = { 'figure': bp.Figure(toolbar_location='right', tools='save,pan,box_zoom,reset', width=250, height=225), 'series': [], } combined_plot['figure'].title.text = 'Combined' combined_plot['figure'].xaxis.major_label_orientation = 'vertical' combined_plot['figure'].xaxis.major_label_standoff = 25 plot_list['combined'] = combined_plot build_plots() if showMaps: build_maps()
def make_figure(output_backend='webgl', tooltips=default_tooltips, tools=default_tools, **kwargs) -> plotting.Figure: """Wrapper for creating bokeh figures that enforces customized default arguments""" return plotting.Figure(output_backend=output_backend, tooltips=tooltips, tools=tools, **kwargs)
def line(self, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, fig=None, **kwds): """Line plot for series data. Parameters ---------- width : int, optional The width of the plot in pixels. height : int, optional The height of the plot in pixels. fig : Figure, optional If specified, the line is added to the existing figure. **kwds : Extra keywords passed to ``line``. Examples -------- >>> series.plot.line(color='blue', alpha=0.5) # doctest: +SKIP Returns ------- fig : bokeh.plotting.Figure """ df = self._data.reset_index() x, y = df.columns = [str(c) for c in df.columns] x_data = df[x] y_data = df[y] axis_kwargs = {} for axis, data in [('x', x_data), ('y', y_data)]: if is_datetime64_any_dtype(data.dtype): axis_kwargs['%s_axis_type' % axis] = 'datetime' elif is_categorical_dtype(data.dtype): raise ValueError("Categorical dtype not supported for line") source = bp.ColumnDataSource({x: x_data, y: y_data}) if fig is None: fig = bp.Figure(plot_height=height, plot_width=width, **axis_kwargs) fig.line(x, y, source=source, **kwds) return fig
content_pdf = content_list + [ (co.FigureMpl(plt.Figure())), (co.FigureMpl(plt.Figure(), output_format="svg")), (co.FigureMpl(plt.Figure(), output_format="svg", pdf_figsize=0.9)), (co.FigureMpl(plt.Figure(), output_format="svg", pdf_figsize=(8, 5))), ] adaptors_extra = [ (_irises_path, co.Image), (Path(_irises_path), co.Image), (pd.DataFrame({ "a": range(1, 11), "b": range(11, 21) }), co.DataFramePd), (plt.figure(), co.FigureMpl), (bkp.Figure(), co.FigureBokeh), (bkl.column(bkp.figure()), co.FigureBokeh), (px.line(x=range(10), y=range(10)), co.FigurePlotly), ] adaptor_list += adaptors_extra @pytest.fixture def content_list_fn(): return content_list @pytest.fixture def layout_list_fn(): return layout_list
bkp.output_file('waveletDemo.html', mode='inline') wave1 = structWave('Ricker25', 'red', 512, 0.5) wave1.typeRicker(25) wave1.calcAmpSpec() wave2 = structWave('BP 5,10,50,70', 'green', 512, 0.5) wave2.typeBandPass(5, 10, 50, 70) wave2.calcAmpSpec() wave3 = structWave('Ormsby 5,10,50,70', 'blue', 512, 0.5) wave3.typeOrmsby(5, 10, 50, 70) wave3.calcAmpSpec() pwave1 = bkp.Figure(title='Time Amplitude', x_axis_label='Time', webgl=True) pwave2 = bkp.Figure(title='Amplitude Spectrum', x_axis_label='Freq', webgl=True) sw1 = bkm.ColumnDataSource(data=dict(time=wave1.timeseries, B=wave1.timeAmp)) sw2 = bkm.ColumnDataSource(data=dict(time=wave2.timeseries, B=wave2.timeAmp)) sw3 = bkm.ColumnDataSource(data=dict(time=wave3.timeseries, B=wave3.timeAmp)) sf1 = bkm.ColumnDataSource(data=dict(freq=wave1.freqseries, B=wave1.ampSpec)) sf2 = bkm.ColumnDataSource(data=dict(freq=wave2.freqseries, B=wave2.ampSpec)) sf3 = bkm.ColumnDataSource(data=dict(freq=wave3.freqseries, B=wave3.ampSpec)) #pwave1.line('time','B',color=wave1.colour,source=sw1) pwave1.line('time', 'B', color=wave2.colour, source=sw2) #pwave1.line('time','B',color=wave3.colour,source=sw3) pwave2.line('freq', 'B', color=wave1.colour, source=sf1)
settingsOutputSize = Slider(start=50, end=500, step=10, value=image['outputSize'], title="Resolution of output image") settingsAlgorithm = Select(options=[ 'roberts', 'sobel', 'scharr', 'prewitt', 'canny-1', 'canny-2', 'canny-3' ], value=image['edgeAlgorithm']) chooseFileLabel = Div(text="""""") chooseFileButton = upload_button() applyChangesButton = Button(label="Apply changes", button_type="primary") applyChangesButton.on_click(callback_modify_output_image) showImageOrig = bp.Figure(plot_width=int(simulation['sizeX']), plot_height=int(simulation['sizeY']), title="Original image", name="original") showImageOrig.toolbar.logo = None showImageOrig.toolbar_location = None showImageOrig.toolbar.active_inspect = None showImageOrig.toolbar.active_scroll = None showImageOrig.toolbar.active_tap = None showImageOrig.toolbar.active_drag = None showImageOrig.x_range = Range1d(start=0, end=simulation['sizeX']) showImageOrig.y_range = Range1d(start=0, end=simulation['sizeY']) showImageOrig.xaxis.visible = None showImageOrig.yaxis.visible = None showImageOrig.xgrid.grid_line_color = None showImageOrig.ygrid.grid_line_color = None showImageResize = bp.Figure(plot_width=int(simulation['sizeX']),
import notebook import numpy as np import pandas as pd from bokeh import plotting with notebook.Notebook() as print: print('Playing with timeseries', fmt='header') dates = pd.date_range('1/1/2018', periods=365) df = pd.DataFrame(np.random.randn(365), index=dates, columns=['deltas']) df['cumsum'] = df.cumsum() print(df) fig = plotting.Figure() fig.line(np.arange(10), np.arange(10), color='blue') # fig.line(df.index.values, df['deltas'].values) print('the figure:', fig)