def pyramid(): xdr = DataRange1d() ydr = FactorRange(factors=groups) plot = Plot(x_range=xdr, y_range=ydr, plot_width=600, plot_height=500, toolbar_location=None) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') plot.add_layout(CategoricalAxis(), 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) m = HBar(left="value", right=0, y="group", height=1, fill_color="#3B8686") mglyph = plot.add_glyph(source_pyramid_m, m) f = HBar(left=0, right="value", y="group", height=1, fill_color="#CFF09E") fglyph = plot.add_glyph(source_pyramid_f, f) plot.add_layout(Legend(items=[("Male", [mglyph]), ("Female", [fglyph])])) return plot
def plot_fva_tva_comparison(fva, tva): all_va = pd.merge(fva, tva, left_index=True, right_index=True) all_va['y'] = range(len(all_va)) source = ColumnDataSource(all_va) xdr = DataRange1d() ydr = DataRange1d() plot = figure(title=None, x_range=xdr, y_range=ydr, plot_width=600, plot_height=1000, h_symmetry=False, v_symmetry=False, min_border=0) glyph_fva = HBar(y="y", right="maximum_x", left="minimum_x", height=0.5, fill_color="#b3de69", fill_alpha=0.5) glyph_tva = HBar(y="y", right="maximum_y", left="minimum_y", height=0.8, fill_color="#2e86c1", fill_alpha=0.5) plot.add_glyph(source, glyph_tva) plot.add_glyph(source, glyph_fva) # Fix ticks label_dict = {} for i, s in enumerate(tva.index): label_dict[i] = s plot.yaxis.formatter = FuncTickFormatter(code=""" var labels = %s; return labels[tick]; """ % label_dict) plot.yaxis.ticker = [x for x in range(len(tva))] return plot
def test_HBar(): glyph = HBar() assert glyph.y is None assert glyph.height is None assert glyph.left == 0 assert glyph.right is None check_fill_properties(glyph) check_line_properties(glyph) check_properties_existence(glyph, [ "y", "height", "left", "right", ], FILL, LINE, GLYPH)
def test_HBar(): glyph = HBar() assert glyph.y is None assert glyph.height is None assert glyph.left == 0 assert glyph.right is None yield check_fill, glyph yield check_line, glyph yield (check_props, glyph, [ "y", "height", "left", "right", ], FILL, LINE)
def test_HBar() -> None: glyph = HBar() assert glyph.y == field("y") assert glyph.height is None assert glyph.left == 0 assert glyph.right is None check_fill_properties(glyph) check_hatch_properties(glyph) check_line_properties(glyph) check_properties_existence(glyph, [ "y", "height", "left", "right", ], FILL, HATCH, LINE, GLYPH)
def modify_doc(doc: Document): source = ColumnDataSource(data=data_holder.get_data()) _keys = data_holder.get_keys() plot = figure(plot_height=600, plot_width=1200, title='Sequence Diagram', x_axis_type='datetime', y_range=_keys, tools="xwheel_zoom,xpan,box_zoom,hover,reset", active_scroll="xwheel_zoom", active_drag="xpan") glyph = HBar(y="who", left="t_start_ms", right="t_end_ms", height=0.4, fill_color="green", fill_alpha=0.2) plot.add_glyph(source, glyph) labels = LabelSet(x="t_start_ms", y="who", text="func", text_font_size="8pt", source=source, text_align='left') plot.add_layout(labels) plot.hover.tooltips = [ ("func", "@func"), ("in", "@in"), ("out", "@out"), # ("msg", "@msg"), ] def callback(): #source.stream(new_data=data_holder.get_data(), rollover=1000) # todo: how to use stream source.data = ColumnDataSource(data=data_holder.get_data()).data doc.add_periodic_callback(callback, 1000) doc.add_root(plot)
def __init__(self, shifts, multiplicities, deviations): self.shifts = shifts self.multiplicities = multiplicities self.deviations = deviations xr = Range1d(start=220, end=-20) self.plot = figure(x_axis_label="ppm", x_range=xr, tools="save,reset", plot_width=self.WIDTH, plot_height=self.HEIGHT) self.lineSource = ColumnDataSource(data=dict(x=[0], y=[0])) self.plot.line('x', 'y', source=self.lineSource, line_width=2) # Remove grid from plot self.plot.xgrid.grid_line_color = None self.plot.ygrid.grid_line_color = None # Remove bokeh logo self.plot.toolbar.logo = None horizontalBoxZoomTool = HorizontalBoxZoomTool() self.plot.add_tools(horizontalBoxZoomTool) fixedZoomOutTool = FixedZoomOutTool(factor=0.4) self.plot.add_tools(fixedZoomOutTool) self.plot.extra_y_ranges['box'] = Range1d(start=0, end=0.1) self.selectionSource = ColumnDataSource(data=dict(left=[], right=[]), callback=CustomJS(code=""" if ('data' in this.selected) { window.top.location.href = "http://localhost:8080?" + this.selected.data.query + "style=plot"; } """)) self.selectionSource.on_change('selected', lambda attr, old, new: self.delete(new['1d']['indices'])) rect = HBar( left='left', right='right', y=0.5, height=1, line_alpha=0.2, fill_alpha=0.2, line_color="red", fill_color="red" ) renderer = self.plot.add_glyph(self.selectionSource, rect) renderer.y_range_name = "box" self.labelSource = ColumnDataSource(data=dict(x=[], y=[], text=[])) label = Text( x='x', y='y', text='text', text_align='center', text_font_size="10pt" ) renderer = self.plot.add_glyph(self.labelSource, label) renderer.y_range_name = "box" removeTool = CustomTapTool() self.plot.add_tools(removeTool) self.plot.toolbar.active_tap = None callback = CustomJS(args=dict(), code=""" /// get BoxSelectTool dimensions from cb_data parameter of Callback var geometry = cb_data['geometry']; var shift = (geometry['x0'] + geometry['x1']) / 2; var deviation = Math.abs(geometry['x1'] - shift); var query = cb_data['query'] + "shift%5B%5D=" + shift + '&multiplicity%5B%5D=any&deviation%5B%5D=' + deviation + '&style=plot'; window.top.location.href = "http://localhost:8080?" + query; """) selectTool = CustomBoxSelectTool( tool_name="Select Area", dimensions = "width", callback = callback, query=self.paramsToQuery() ) self.plot.add_tools(selectTool) self.initSelect() self.drawButton = CustomButton(id='myButton') self.drawButton.on_click(self.drawPlot) curdoc().add_root( row( column(row(self.plot)), column(CustomRow(column(self.drawButton), hide=True)) ) )
def init_plot(): cprint('%s: init barcharts per neighbourhood...' % TAG, 'yellow', attrs=['bold']) init_wordcount() global prefix_count global wword_count global word_barplots global word_sources global mapper global svg_div init_user_plot() init_mention_plot() count_words(prefix_count, wword_count) # update colorbar min_freq, max_freq = get_freq_range(prefix_count) mapper['transform'].low = min_freq mapper['transform'].high = max_freq # update colorbar tickers steps = 13 while max_freq < steps: steps = steps // 2 color_bar.ticker = FixedTicker( ticks=np.linspace(min_freq, max_freq, steps, dtype=np.int)) y = np.arange(config.NUM_WORD_BARS) for i, (neigh, wcount) in enumerate(prefix_count.items()): wordfreqlist = sorted(wcount.items(), key=lambda kv: kv[1], reverse=True) x = [] prefixes = [] wlist = [] for prefix, freq in wordfreqlist[:config.NUM_WORD_BARS]: x.append(freq) prefixes.append(prefix) wlist.append([' %s:%d' % (k,v) \ for (k,v) in sorted(wword_count[neigh][prefix].items(), key=lambda kv:kv[1], reverse=True)[:5]]) color_index = np.round( minmax_scale([np.mean(x[:5]), min_freq, max_freq], feature_range=(0, 5))[0]) map_fill_color = Spectral6[np.int(color_index)] svg.change_fill_color(neigh.replace(' ', ''), map_fill_color) plt = word_barplots[i] src = word_sources[i] src.data = dict(y=y, right=x, wlist=wlist) t = Title() t.text = neigh.title()[:13] plt.title = t glyph = HBar(y='y', right='right', left=0, height=0.90, fill_color=mapper) word_hbarglyphs.append(glyph) plt.add_glyph(src, glyph) xaxis = LinearAxis() xaxis.ticker = np.linspace(0, max(x), 5, dtype=np.int)[1:] plt.add_layout(xaxis, 'below') plt.xaxis.major_label_orientation = +np.pi / 2 yaxis = LinearAxis() yaxis.ticker = y yaxis.major_label_overrides = { i: prefix for i, prefix in enumerate(prefixes) } yaxis.major_label_standoff = -35 plt.add_layout(yaxis, 'left') plt.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plt.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) svg_div.text = svg.to_string()
def plot_va(filename, tag, kind, color=DEFAULT_COLOR, orient='horizontal'): bp.curdoc().clear() title = verbose_kinds[kind] + ' variability analysis for {} iJO1366 model'\ .format(tag) data = pd.read_csv(os.path.join(outputs_folder, filename), index_col=0) if not data.columns[0] in ['minimum', 'maximum']: data.columns = ['minimum', 'maximum'] data += 1e-9 # Resolution of the solver f = lambda x: np.sqrt(x[0] * x[1]) # data['score'] = data.mean(axis=1) data['score'] = data.apply(f, axis=1) data.sort_values(by='score', ascending=False, inplace=True) data['y'] = range(len(data)) data['name'] = data.index source = ColumnDataSource(data) xdr = DataRange1d() ydr = DataRange1d() _tools_to_show = 'box_zoom,pan,save,hover,reset,tap,wheel_zoom' if orient == 'vertical': p1 = bp.figure( title=title, x_range=xdr, y_range=ydr, x_axis_type='log', plot_width=600, plot_height=1000, tools=_tools_to_show, # h_symmetry=False, v_symmetry=False, min_border=0) glyph = HBar(y="y", right="maximum", left="minimum", height=0.9, fill_color=color, fill_alpha=0.5, line_color=None) p1.add_glyph(source, glyph) p1.circle(x='score', y='y', fill_color=color, line_color=None, source=source) axis1 = p1.xaxis axis2 = p1.yaxis elif orient == 'horizontal': p1 = bp.figure( title=title, x_range=ydr, y_range=xdr, y_axis_type='log', plot_width=1000, plot_height=600, tools=_tools_to_show, # h_symmetry=False, v_symmetry=False, min_border=0) glyph = VBar(x="y", top="maximum", bottom="minimum", width=0.9, fill_color=color, fill_alpha=0.5, line_color=None) p1.add_glyph(source, glyph) p1.circle(y='score', x='y', fill_color=color, line_color=None, source=source) axis1 = p1.yaxis axis2 = p1.xaxis else: raise ValueError("orient should be 'vertical' or 'horizontal'") # Fix ticks label_dict = {} for i, s in enumerate(data.index): label_dict[i] = s axis2.formatter = FuncTickFormatter(code=""" var labels = %s; return labels[tick]; """ % label_dict) axis1.axis_label = '[{}]'.format(verbose_kinds[kind]) # p1.yaxis.ticker = [x for x in range(len(data))] hover = p1.select(dict(type=HoverTool)) hover.tooltips = [ (verbose_kinds[kind], "@name"), ("min", "@minimum"), ("max", "@maximum"), ] hover.mode = 'mouse' path = os.path.join(plots_folder, 'va_' + filename) bp.output_file(path + '.html') bp.show(p1) p1.output_backend = 'svg' export_svgs(p1, filename=path + '.svg') bp.curdoc().clear() return data
data['Method 4 (LR)'] = meth4list techs = ['org', 'meth1', 'meth2', 'meth3', 'meth4'] #Initializing it for method 1. This gets controlled by the drop box selector source1 = ColumnDataSource(dict(y=cols, right=orglist, compare=meth1list)) p2 = figure( plot_width=700, plot_height=300, title="Estimated Values of Method 1 (GC) Vs Predicted Value Bar Chart", y_range=cols, x_range=(-2, 10000)) glyph = HBar(y="y", right="right", left=0, height=0.5, fill_color="#99d594", fill_alpha=0.6) p2.add_glyph(source1, glyph) glyph1 = HBar(y="y", right="compare", left=0, height=0.5, fill_color="#d53e4f", fill_alpha=0.6) p2.add_glyph(source1, glyph1) p2.xaxis.axis_label = "Money Spent" p2.yaxis.axis_label = "Missing value's Product"
def generate_single_table(df, time_str, color_dict, colors): fill = [ color_dict[model_key] if model_key in color_dict else 'grey' for model_key in df.model ] data = dict(manufacturer=[m for m in df['manufacturer']], color=[c for c in df['color']], model=[m for m in df['model']], failure_rate=[np.round(f, 2) for f in df['failure_rate']], count=[c for c in df['count']]) source = ColumnDataSource(data) columns = [ TableColumn(field="manufacturer", title="manufacturer"), TableColumn(field="model", title="model"), TableColumn(field="count", title="count"), TableColumn(field="failure_rate", title="failure rate") ] #TableColumn(field="model", title="model"), xdr = Range1d(start=0, end=20) ydr = Range1d(start=-2, end=2) title = 'Failure Rate' bar_fig = figure(title=title, x_range=xdr, y_range=ydr, width=270, height=570) table_plot = DataTable(source=source, columns=columns, width=640, height=700, row_headers=False, sortable=False) #, x_range=xdr, y_range=ydr) #table_plot.font.text_font_size = 14 bar_data = dict(manufacturer=[m for m in df['manufacturer']], color=[c for c in df['color']], y=np.linspace(1.9, -1.8, len(df)), right=[np.round(f, 2) for f in df['failure_rate']], count=[c for c in df['count']]) bar_source = ColumnDataSource(bar_data) bar_plot = HBar( y='y', right='right', left=0, height=.14, fill_color='color', line_color='white' ) #, tools=['hover'], outline_line_color="color", border_fill_color='color', color='color', legend=None) #bar_plot.grid.grid_line_alpha = 0 #bar_plot .ygrid.band_fill_color = None #bar_plot .ygrid.band_fill_alpha = 0.1 #bar_plot.x_range.range_padding = 0 bar_fig.add_glyph(bar_source, bar_plot) bar_fig.min_border_top = 0 bar_fig.yaxis.visible = False #plot.xaxis.axis_line_width = 2 #plot.yaxis.axis_line_width = 2 bar_fig.title.text_font_size = '16pt' #plot.xaxis.axis_label_text_font_size = "14pt" #plot.xaxis.major_label_text_font_size = "14pt" #plot.yaxis.axis_label_text_font_size = "14pt" #plot.yaxis.major_label_text_font_size = "14pt" bar_fig.ygrid.grid_line_color = None bar_fig.xgrid.grid_line_color = None bar_fig.toolbar.logo = None bar_fig.outline_line_width = 0 bar_fig.outline_line_color = "white" layout = row(table_plot, bar_fig) return layout
def plot_dist_box_by_cols(summary_df, measure_name, cols_to_plot, col_groupname, colnames=None, title=None, horizontal=True, cmap="Spectral", palette=None, bgcolor="#D9EEF1", plot_range=None, plot_size=None, linked_plot=None, out_html=None, nolegend=False): ''' Build boxplot ''' # We only need cols_to_plot # Note that it uses idx values and name to label scatter points df_toplot = summary_df[cols_to_plot] # default title if title is None: title = '%s by %s' % (measure_name, col_groupname) # Stack them to prepare for plotting stacked = stack_df(df_toplot, cols_to_plot, col_groupname, measure_name) # find the quartiles and IQR for each category groups = stacked.groupby(col_groupname) mean = groups.mean() count = groups.count() q1 = groups.quantile(q=0.25) q2 = groups.quantile(q=0.5) q3 = groups.quantile(q=0.75) iqr = q3 - q1 upper = q3 + 1.5 * iqr lower = q1 - 1.5 * iqr # find the outliers for each category def outliers(group): cat = group.name return group[(group[measure_name] > upper.loc[cat][measure_name]) | ( group[measure_name] < lower.loc[cat][measure_name])][measure_name] out = groups.apply(outliers).dropna() # if no outliers, shrink lengths of stems to be no longer than the minimums or maximums qmin = groups.quantile(q=0.00) qmax = groups.quantile(q=1.00) upper.loc[:, measure_name] = [ min([x, y]) for (x, y) in zip(list(qmax.loc[:, measure_name]), upper.loc[:, measure_name]) ] lower.loc[:, measure_name] = [ max([x, y]) for (x, y) in zip(list(qmin.loc[:, measure_name]), lower.loc[:, measure_name]) ] # Put them in a single df to create a datasource for box plots box_source = pd.concat([mean, count, q1, q2, q3, iqr, upper, lower], axis=1) box_source.columns = [ 'mean', 'count', '25p', '50p', '75p', 'IQR', 'upper', 'lower' ] box_source = ColumnDataSource(box_source) # if there are outliers, put them in a single df to create a datasource for # outlier scatter plots if not out.empty: out_dat = {} for cat in cols_to_plot: if not out.loc[cat].empty: num_out = len(out.loc[cat]) out_dat[col_groupname] = out_dat.get(col_groupname, []) + [cat] * num_out out_dat[out.loc[cat].index.name] = out_dat.get( out.loc[cat].index.name, []) + (out.loc[cat].index.tolist()) out_dat[measure_name] = out_dat.get( measure_name, []) + (out.loc[cat].values.tolist()) out_source = ColumnDataSource(pd.DataFrame(out_dat)) # Categorical color mapper # If palette is provided, it overrides cmap if palette is not None: my_palette = palette else: my_palette = get_bokehpalette(cmap, len(cols_to_plot)) color_mapper = CategoricalColorMapper(factors=cols_to_plot, palette=my_palette) # properties for color etc. style_d = dict(fill_color={ 'field': col_groupname, 'transform': color_mapper }, fill_alpha=0.5, line_color='slategray') hover_style_d = dict(fill_color={ 'field': col_groupname, 'transform': color_mapper }, fill_alpha=0.9, line_color='black') # Set the plot range on the measure dimension if plot_range is not given if plot_range is None: plot_range = get_lims(stacked[measure_name].values) measure_range = Range1d(plot_range[0], plot_range[1]) very_thin_range = 0.001 * (plot_range[1] - plot_range[0]) # plot top to bottom if horizontal if horizontal: y_range = cols_to_plot[::-1] if plot_size is None: plot_size = (800, 80 + 50 * len(y_range)) p = figure(plot_width=plot_size[0], plot_height=plot_size[1], x_range=measure_range, y_range=y_range, title=title, background_fill_color=bgcolor) # components for vertically arranged horizontal boxplots seg1_d = dict(x0='25p', y0=col_groupname, x1='lower', y1=col_groupname) seg2_d = dict(x0='75p', y0=col_groupname, x1='upper', y1=col_groupname) box = HBar(y=col_groupname, right='75p', left='25p', height=0.5, line_width=2, **style_d) box_h = HBar(y=col_groupname, right='75p', left='25p', height=0.5, line_width=2, **hover_style_d) whisk1_d = dict(x='lower', y=col_groupname, width=very_thin_range, height=0.2) whisk2_d = dict(x='upper', y=col_groupname, width=very_thin_range, height=0.2) whisk3_d = dict(x='mean', y=col_groupname, width=very_thin_range, height=0.5) whisk4_d = dict(x='50p', y=col_groupname, width=very_thin_range, height=0.5) scatter = Circle(x=measure_name, size=8, y=jitter(col_groupname, width=0.6, range=p.y_range), **style_d) scatter_h = Circle(x=measure_name, size=8, y=jitter(col_groupname, width=0.6, range=p.y_range), **hover_style_d) p.xaxis.axis_label = "%s" % measure_name else: x_range = cols_to_plot if plot_size is None: plot_size = (80 + 50 * len(x_range), 800) p = figure(plot_width=plot_size[0], plot_height=plot_size[1], x_range=x_range, y_range=measure_range, title=title, background_fill_color=bgcolor) # components for horizontally arranged vertical boxplots seg1_d = dict(x0=col_groupname, y0='25p', x1=col_groupname, y1='lower') seg2_d = dict(x0=col_groupname, y0='75p', x1=col_groupname, y1='upper') box = VBar(x=col_groupname, top='75p', bottom='25p', width=0.5, line_width=2, **style_d) box_h = VBar(x=col_groupname, top='75p', bottom='25p', width=0.5, line_width=2, **hover_style_d) whisk1_d = dict(x=col_groupname, y='lower', width=0.2, height=very_thin_range) whisk2_d = dict(x=col_groupname, y='upper', width=0.2, height=very_thin_range) whisk3_d = dict(x=col_groupname, y='mean', width=0.5, height=very_thin_range) whisk4_d = dict(x=col_groupname, y='50p', width=0.5, height=very_thin_range) scatter = Circle(x=jitter(col_groupname, width=0.6, range=p.y_range), y=measure_name, size=8, **style_d) scatter_h = Circle(x=jitter(col_groupname, width=0.6, range=p.y_range), y=measure_name, size=8, **hover_style_d) p.yaxis.axis_label = "%s" % measure_name # Now plot the box by each component p.segment(line_color='slategray', line_width=4, source=box_source, **seg1_d) p.segment(line_color='slategray', line_width=4, source=box_source, **seg2_d) p.rect(line_color='slategray', line_width=4, source=box_source, **whisk1_d) p.rect(line_color='slategray', line_width=4, source=box_source, **whisk2_d) p.rect(line_color='slategray', source=box_source, **whisk3_d) p.rect(line_color='slategray', line_width=4, source=box_source, **whisk4_d) box_glyph = GlyphRenderer(data_source=box_source, glyph=box, hover_glyph=box_h) # Make and add the hover tool box_tooltips = [(col_groupname, '@%s' % col_groupname), ('count', '@count'), ('mean', '@mean'), ('median', '@50p'), ('IQR', '@IQR'), ('upper', '@upper'), ('lower', '@lower')] box_hover = HoverTool(renderers=[box_glyph], tooltips=box_tooltips) p.add_tools(box_hover) p.renderers.extend([box_glyph]) # Plot outliers if any if not out.empty: out_scatter = GlyphRenderer(data_source=out_source, glyph=scatter, hover_glyph=scatter_h) scatter_tooltips = [(df_toplot.index.name, '@%s' % df_toplot.index.name), (col_groupname, '@%s' % col_groupname), ('%s value' % measure_name, '@%s' % measure_name)] scat_hover = HoverTool(renderers=[out_scatter], tooltips=scatter_tooltips) p.add_tools(scat_hover) p.renderers.extend([out_scatter]) p.min_border = 10 #5 #p.min_border_bottom = 100 if nolegend: p.yaxis.visible = False p.min_border_left = 60 p.min_border_right = 60 if out_html is not None: bokeh.io.save(p, filename=out_html, title=title) return p
women = [-x for x in total_emmigr_women_data.values.tolist()[0]] source_w = ColumnDataSource(data=dict( years=years, women=women, )) # "Emmigrants Men / Women[2014-2017] plot1 = Plot(title=None, plot_width=700, plot_height=600, min_border=0, toolbar_location=None) glyph_m = HBar(y="years", right="men", left=1000, height=0.31, fill_color=Category20[10][0]) plot1.add_glyph(source_m, glyph_m) glyph_w = HBar(y="years", left="women", right=-1000, height=0.31, fill_color=Category20[10][1]) plot1.add_glyph(source_w, glyph_w) xaxis = LinearAxis() plot1.add_layout(xaxis, 'below') yaxis = LinearAxis() plot1.add_layout(yaxis, 'left')
def render_bar_plot(source, plt_title): """Renders a bokeh bar plot from a data source. Args: source (dataframe): A dict-style Pandas dataframe. plt_title (str): Title for the plot. Returns: Components of a bar plot figure. """ bar_height = 0.5 top_stop = len(source.data["tick_labels"]) - 1 + bar_height bottom_start = -1 * bar_height xdr = DataRange1d() ydr = DataRange1d(start=bottom_start, end=top_stop) plot = figure(title=plt_title, x_range=xdr, y_range=ydr, plot_width=1200, plot_height=1200, h_symmetry=False, v_symmetry=False, toolbar_location=None, y_axis_type=None, x_axis_type=None) # Add vertical bar glyphs to the plot. glyph = HBar(y="provider_idx", right="outlier_count", left=0, height=bar_height, fill_color="#DB4437") plot.add_glyph(source, glyph) # Need to convert provider names to tick labels. yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=1), axis_line_color='white', major_tick_line_color='white', minor_tick_line_color='white') plot.add_layout(yaxis, 'left') plot.yaxis.major_label_overrides = { idx: label for idx, label in enumerate(source.data["tick_labels"]) } # Add some labels to the bar plots labels = LabelSet(x='outlier_count', y='provider_idx', x_offset=5, y_offset=-8, text='outlier_count', source=source, text_font_size='18pt') plot.add_layout(labels) # Making the plot pretty plot.title.text_font_size = '40pt' plot.yaxis.axis_label_text_font_size = '30pt' plot.yaxis.major_label_text_font_size = '18pt' plot.xaxis.axis_label = "Anomaly Count" plot.outline_line_color = None # Rotating the plot labels so that the text fit # plot.xaxis.major_label_orientation = pi/3 return components(plot)
source2 = ColumnDataSource(data=dict(x=x, y=y)) # Set up plot plot = figure(plot_height=400, plot_width=800, title="Population", tools="crosshair,pan,reset,save,wheel_zoom", y_axis_label="Age", x_axis_label="Percentage of the total population", x_range=ranges.Range1d(start=-.01, end=.01), y_range=ranges.Range1d(start=-1, end=102)) glyph1 = HBar(y="y_m", right="right_m", left=0, height=0.5, fill_color="blue", name="Male") plot.add_glyph(source, glyph1) glyph2 = HBar(y="y_f", right="right_f", left=0, height=0.5, fill_color="orange", name="Female") plot.add_glyph(source, glyph2) plot.xaxis.bounds = (-.01, .01) plot7 = figure(plot_height=400,
)) xdr = DataRange1d() ydr = DataRange1d() plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=300, plot_height=300, h_symmetry=False, v_symmetry=False, min_border=0, toolbar_location=None) glyph = HBar(y="y", right="right", left=0, height=0.5, fill_color="#b3de69") plot.add_glyph(source, glyph) xaxis = LinearAxis() 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)) doc = Document() doc.add_root(plot) show(plot)
x_ = rand_jitter(x) y_ = rand_jitter(y) s2.step(x_, y_, color="firebrick", alpha=0.5) # "heatmap" for V s3 = figure(plot_width=250, plot_height=250, title=None) x = list(np.linspace(0, 1, 10)) * 10 y = [[i] * 10 for i in np.linspace(0, 1, 10)] y = [a for b in y for a in b] s3.add_layout(Whisker(base=0.5, upper=0.9, lower=0.1)) # create and another s4 = figure(plot_width=250, plot_height=250, title=None) y = np.linspace(0.2, 0.8, 5) right = np.array([0.8, 0.1, 0.8, 0.1, 0.8]) src = ColumnDataSource(dict(y=y, right=right)) s4.add_glyph( src, HBar(y="y", right="right", left=0, height=0.1, fill_color="#b3de69")) for s in [s1, s2, s3, s4]: s.axis.visible = False s.toolbar.logo = None s.toolbar_location = None s.x_range = Range1d(0, 1) s.y_range = Range1d(0, 1) s4.x_range = Range1d(-0.1, 0.9) # put the results in a row show(row(s1, s2, s3, s4))