def _addlegend(self): # Add the color bar if 'z_axis_type' in pytplot.data_quants[self.tvar_name].zaxis_opt: if pytplot.data_quants[self.tvar_name].zaxis_opt['z_axis_type'] == 'log': color_mapper = LogColorMapper(palette=self.colors[0], low=self.zmin, high=self.zmax) color_bar = ColorBarSideTitle(color_mapper=color_mapper, ticker=LogTicker(), border_line_color=None, location=(0, 0)) color_bar.formatter = BasicTickFormatter(precision=2) else: color_mapper = LinearColorMapper(palette=self.colors[0], low=self.zmin, high=self.zmax) color_bar = ColorBarSideTitle(color_mapper=color_mapper, ticker=BasicTicker(), border_line_color=None, location=(0, 0)) color_bar.formatter = BasicTickFormatter(precision=4) else: color_mapper = LogColorMapper(palette=self.colors[0], low=self.zmin, high=self.zmax) color_bar = ColorBarSideTitle(color_mapper=color_mapper, ticker=LogTicker(), border_line_color=None, location=(0, 0)) color_bar.formatter = BasicTickFormatter(precision=2) color_bar.width = 10 color_bar.major_label_text_align = 'left' color_bar.label_standoff = 5 color_bar.major_label_text_baseline = 'middle' color_bar.title = pytplot.data_quants[self.tvar_name].zaxis_opt['axis_label'] color_bar.title_text_font_size = str(pytplot.data_quants[self.tvar_name].extras['char_size'])+'pt' color_bar.title_text_font_style = 'bold' color_bar.title_standoff = 20 self.fig.add_layout(color_bar, 'right')
def test_displays_title_scientific(self, bokeh_model_page) -> None: slider = RangeSlider(start=0, end=10e-6, step=1e-6, value=(1e-6, 8e-6), title="bar", format=BasicTickFormatter(precision=2), css_classes=["foo"], width=300) page = bokeh_model_page(slider) el = page.driver.find_element_by_css_selector('.foo') assert len( el.find_elements_by_css_selector('div.bk-input-group > div')) == 2 # XXX: WebElement.text returns undecoded UTF-8 byte strings as str (!) (not bytes) def decode(s: str) -> str: return bytes(map(ord, s)).decode("utf-8") t0 = decode(get_slider_title_text(page.driver, ".foo")) t1 = decode(get_slider_title_value(page.driver, ".foo")) assert t0 == "bar: 1.00e\u22126 .. 8.00e\u22126" assert t1 == "1.00e\u22126 .. 8.00e\u22126" assert page.has_no_console_errors()
def test_displays_title_scientific(self, bokeh_model_page) -> None: slider = RangeSlider(start=0, end=10e-6, step=1e-6, value=(1e-6, 8e-6), title="bar", format=BasicTickFormatter(precision=2), css_classes=["foo"], width=300) page = bokeh_model_page(slider) el = page.driver.find_element_by_css_selector('.foo') assert len(el.find_elements_by_css_selector('div.bk-input-group > div')) == 2 assert get_title_text(page.driver, ".foo") == "bar: 1.00e-6 .. 8.00e-6" assert get_title_value(page.driver, ".foo") == "1.00e-6 .. 8.00e-6" assert page.has_no_console_errors()
def test_displays_title_scientific( self, bokeh_model_page: BokehModelPage) -> None: slider = RangeSlider(start=0, end=10e-6, step=1e-6, value=(1e-6, 8e-6), title="bar", format=BasicTickFormatter(precision=2), width=300) page = bokeh_model_page(slider) children = find_elements_for(page.driver, slider, "div.bk-input-group > div") assert len(children) == 2 t0 = get_slider_title_text(page.driver, slider) t1 = get_slider_title_value(page.driver, slider) assert t0 == "bar: 1.00e\u22126 .. 8.00e\u22126" assert t1 == "1.00e\u22126 .. 8.00e\u22126" assert page.has_no_console_errors()
r1 = p.line([], [], color="yellow", line_width=line_width, y_range_name = "pressures") r2 = p.line([], [], color="skyblue", line_width=line_width, y_range_name = "temps") r3 = p.line([], [], color="green", line_width=line_width, y_range_name = "temps") #print('\n'*5, r1.data_source.properties_with_values()['data']['x'], '\n'*5) ## For each new range add it here p.extra_y_ranges = {"temps": DataRange1d(only_visible = True, renderers = [r2,r3], range_padding_units = 'percent',range_padding = range_scale), "pressures": DataRange1d(only_visible = True, renderers = [r1], range_padding_units = 'percent',range_padding = range_scale)} p.add_layout(LinearAxis(y_range_name="temps", axis_label = "Temps"), 'left') p.add_layout(LinearAxis(y_range_name="pressures", axis_label = "Pressures"), 'left') p.yaxis.formatter = BasicTickFormatter(precision = 1) p.grid.grid_line_color = 'gray' p.grid.minor_grid_line_alpha = 0.4 p.grid.grid_line_alpha = 0.4 ################################# #Add data here ################################# #r1 = p.line([Start_Time], [0], color="yellow", line_width=2, y_range_name = "pressures") #r2 = p.line([Start_Time], [0], color="skyblue", line_width=2, y_range_name = "temps") legend = Legend(items=[("One" , [r1]), ("Two" , [r2]),
def timing_plot(genfn): "Draw a timing plot for a prime generator function" if not check_fn(genfn): return global _lines def plot(fig, name, vals, num, dash='solid'): "Add a line with points to a plot" col = _palette[num % len(_palette)] fig.line('x', 'y', legend_label=name, source=vals, line_dash=dash, color=col) fig.scatter('x', 'y', legend_label=name, source=vals, marker='o', color=col) name = genfn.__name__ exist = None args = dict(plot_width=800, plot_height=400, toolbar_location='above', title="Timing") linfig = figure(y_range=[0, 1], x_range=DataRange1d(start=0), **args) logfig = figure(y_range=[1e-6, 1], x_range=DataRange1d(start=1), x_axis_type='log', y_axis_type='log', **args) num = 0 # add previous lines for k, v in _lines.items(): plot(linfig, k, v, num, 'dashed') plot(logfig, k, v, num, 'dashed') if k == name: exist = num num += 1 source = ColumnDataSource(data=dict(x=[], y=[])) for fig in (linfig, logfig): plot(fig, name, source, exist or num) fig.xaxis.axis_label = "Primes" fig.xaxis.formatter = NumeralTickFormatter(format='0[.]0 a') fig.xgrid.minor_grid_line_color = 'lightgrey' fig.xgrid.minor_grid_line_alpha = 0.2 fig.yaxis.axis_label = "Seconds" fig.legend.location = 'bottom_right' fig.legend.click_policy = 'hide' fig.legend.background_fill_alpha = 0.5 linfig.yaxis.formatter = BasicTickFormatter() logfig.yaxis.formatter = BasicTickFormatter(use_scientific=True, precision=0) lintab = Panel(child=linfig, title="Linear") logtab = Panel(child=logfig, title="Log") tabs = Tabs(tabs=[lintab, logtab]) handle = None if _incremental: # Incremental: show plot now, then incrementally add points handle = show(tabs, notebook_handle=True) try: genfn() combined = True except TypeError: combined = False if combined: # Generate line in one go plot_line_combined(genfn, source, handle) else: # Generator takes size, need to generate points separately plot_line_separate(genfn, source, handle) if not _incremental: # Plot not shown yet, show it now show(tabs) # save line data to show on next plot _lines[name] = source.data
x2 = np.linspace(1.5, 5.5, 5) z = x2 + 2 * np.cos((x2 - 1) * np.pi) source1 = ColumnDataSource({ "x": [1, 2, 3, 4, 5], "y": [1, 2, 3, 4, 5], "who": ["a", "b", "c", "d", "e"] }) source2 = ColumnDataSource({"x": x, "y": y}) source3 = ColumnDataSource({"x": x2, "y": z}) source4 = ColumnDataSource({"y": [2.5], "x": [0.5]}) plot = Plot(width=300, height=300) plot.title = Title(text="Themed glyphs") xaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter()) yaxis = LinearAxis(ticker=BasicTicker(), formatter=BasicTickFormatter()) plot.add_layout(xaxis, "below") plot.add_layout(yaxis, "left") plot.add_glyph(source1, Scatter(x="x", y="y", marker="diamond", size=20)) plot.add_glyph(source1, Text(x=dodge("x", -0.2), y=dodge("y", 0.1), text="who")) plot.add_glyph(source2, Line(x="x", y="y")) plot.add_glyph(source3, Ellipse(x="x", y="y", width=0.2, height=0.3, angle=-0.7)) plot.add_glyph(source4, glyph=HBar(y="y", right="x", height=1.5))
right='Count', height=0.6, source=source_emp, color='color') panel_emp = Panel(child=p_emp, title="Top Sponsor") # plot, tools, panel (top titles) p_title = figure( y_range=df_title['JOB_TITLE'][-top_n_plot:].tolist(), plot_height=600, plot_width=800, x_axis_label='Quantity', title="Top {} Sponsored Job Titles (2015-2017)".format(top_n_plot), tools='ywheel_zoom, xwheel_zoom, pan, save, reset', active_scroll='ywheel_zoom') p_title.xaxis[0].formatter = BasicTickFormatter( use_scientific=False) # disable scientific notation p_title.add_tools( HoverTool(tooltips=[('job title', '@JOB_TITLE'), ('frequency', '@Count')])) p_title.hbar(y='JOB_TITLE', right='Count', height=0.6, source=source_title, color='color') panel_title = Panel(child=p_title, title="Top Job Title") # ============================================================================= # search box, message, button, data table, match table # ============================================================================= search_employer = TextInput(value='', title="Sponsor Search (separate by comma):") search_title = TextInput(value='', title="Title Search (separate by comma):")