def layout_padding(plots, renderer): """ Pads Nones in a list of lists of plots with empty plots. """ widths, heights = defaultdict(int), defaultdict(int) for r, row in enumerate(plots): for c, p in enumerate(row): if p is not None: width, height = renderer.get_size(p) widths[c] = max(widths[c], width) heights[r] = max(heights[r], height) expanded_plots = [] for r, row in enumerate(plots): expanded_plots.append([]) for c, p in enumerate(row): if p is None: x_range = Range1d(start=0, end=1) y_range = Range1d(start=0, end=1) p = Figure(plot_width=widths[c], plot_height=heights[r], x_range=x_range, y_range=y_range) p.xaxis.visible = False p.yaxis.visible = False p.outline_line_alpha = 0 p.grid.grid_line_alpha = 0 expanded_plots[r].append(p) return expanded_plots
def empty_plot(width, height): """ Creates an empty and invisible plot of the specified size. """ x_range = Range1d(start=0, end=1) y_range = Range1d(start=0, end=1) p = Figure(plot_width=width, plot_height=height, x_range=x_range, y_range=y_range) p.xaxis.visible = False p.yaxis.visible = False p.outline_line_alpha = 0 p.grid.grid_line_alpha = 0 return p
def style_snapshot(figure: Figure) -> Figure: """Style a bokeh figure as a configuration snapshot. This is collection of style changes to make the output of a snapshot consistent and nice. Primarily it removes all the extra stuff which isn't helpful in defining the configuration like the axes, and the interactive tools. """ figure.axis.visible = False figure.xgrid.visible = False figure.ygrid.visible = False figure.toolbar_location = None figure.toolbar.logo = None figure.outline_line_width = 0 figure.outline_line_alpha = 0 return figure
def make_axis(axis, size, factors, dim, flip=False, rotation=0, label_size=None, tick_size=None, axis_height=35): factors = list(map(dim.pprint_value, factors)) nchars = np.max([len(f) for f in factors]) ranges = FactorRange(factors=factors) ranges2 = Range1d(start=0, end=1) axis_label = dim_axis_label(dim) reset = "range.setv({start: 0, end: range.factors.length})" ranges.callback = CustomJS(args=dict(range=ranges), code=reset) axis_props = {} if label_size: axis_props['axis_label_text_font_size'] = value(label_size) if tick_size: axis_props['major_label_text_font_size'] = value(tick_size) tick_px = font_size_to_pixels(tick_size) if tick_px is None: tick_px = 8 label_px = font_size_to_pixels(label_size) if label_px is None: label_px = 10 rotation = np.radians(rotation) if axis == 'x': align = 'center' # Adjust height to compensate for label rotation height = int(axis_height + np.abs(np.sin(rotation)) * ((nchars * tick_px) * 0.82)) + tick_px + label_px opts = dict(x_axis_type='auto', x_axis_label=axis_label, x_range=ranges, y_range=ranges2, plot_height=height, plot_width=size) else: # Adjust width to compensate for label rotation align = 'left' if flip else 'right' width = int(axis_height + np.abs(np.cos(rotation)) * ((nchars * tick_px) * 0.82)) + tick_px + label_px opts = dict(y_axis_label=axis_label, x_range=ranges2, y_range=ranges, plot_width=width, plot_height=size) p = Figure(toolbar_location=None, **opts) p.outline_line_alpha = 0 p.grid.grid_line_alpha = 0 if axis == 'x': p.yaxis.visible = False axis = p.xaxis[0] if flip: p.above = p.below p.below = [] p.xaxis[:] = p.above else: p.xaxis.visible = False axis = p.yaxis[0] if flip: p.right = p.left p.left = [] p.yaxis[:] = p.right axis.major_label_orientation = rotation axis.major_label_text_align = align axis.major_label_text_baseline = 'middle' axis.update(**axis_props) return p
def importance_plot(dates, ratings, importance, reviews, bad_words): """This plot generates the figure seen on the YelpHelp website. It plots a review history, in which potential tipping point reviews are plotted with inflated circles. It also defines a hover-tool tip allowing one to visualize the full text of the review by mousing over a point, as well as the keywords the model found important contained within the review.""" min_size = 8 max_growth = 32 importance = np.round((max_growth * importance) + min_size) source = ColumnDataSource( data=dict( desc=reviews, bad=bad_words, ratings_source=np.zeros(len(ratings)) ) ) # Create the figure! title_string = 'Review History' review_plot = Figure(plot_width=600, plot_height=600, x_axis_type="datetime", tools=[], responsive=True, toolbar_location=None,webgl=True,title=title_string) cr = review_plot.circle(dates, ratings, size=importance, color="navy", hover_fill_color="firebrick", fill_alpha=0.9, hover_alpha=0.9, line_color=None, hover_line_color="white", source=source) hover = HoverTool( tooltips=""" <link href="../static/css/bootstrap.min.css" rel="stylesheet"> <div> <div style="font-family: verdana; width : 550px; position: fixed; left: 650px; top: 180px; padding: 10px"> <span style="font-size: 17px;"> <b>Review: </b> @desc</span> </div> <div style="font-family: verdana; width : 550px; position: fixed; left: 650px; top: 120px; padding: 10px"> <span style="font-size: 14px; font-weight: bold;"> Keywords: @bad</span> </div> </div>""", renderers=[cr] ) review_plot.add_tools(hover) newdate = pd.date_range(dates.max(), periods=5, freq='120D') projected_mean = 0 # estimated_switch[-1] projection_uncertainty = 20 # np.round(estimated_sigma * 2 * 10) review_plot.xaxis.axis_label = "Date" review_plot.xaxis.axis_line_width = 3 review_plot.xaxis.axis_label_text_font_style = "bold" review_plot.xaxis.axis_label_text_font_size = '20pt' review_plot.xaxis.major_label_text_font_size = '16pt' review_plot.yaxis.axis_line_width = 3 review_plot.yaxis.axis_label_text_font_style = "bold" review_plot.yaxis.axis_label_text_font_size = '20pt' review_plot.yaxis.ticker = FixedTicker(ticks=[-3, -2, -1, 0, 1, 2, 3]) review_plot.yaxis.major_label_text_font_size = '16pt' review_plot.xgrid.visible = False review_plot.ygrid.visible = False review_plot.outline_line_alpha = 0 review_plot.xaxis.axis_label = 'Date Posted' review_plot.yaxis.axis_label = 'Rating (Normed to User Average)' review_plot.title.text_font_size = '16pt' review_plot.title.align='center' #rolling_ratings, edited_dates, interp_ratings, samplerange = rolling_average_rating(business_reviews, 100) # show the results return review_plot
button.on_click(button_fun) rbutton.on_click(init) init() create_orig(orig) ps = 0.3 plot = Figure(tools = "",title="Maxwell",title_location = "above", x_range=(0.1-ps,0.8+ps), y_range=(0.0,1.0)) plot.line(x='x', y='y', source=orig.pts, color='Black',line_width=3) plot.line(x='x', y='y', source=f1.pts, color="#808080",line_width=5) plot.line(x='x', y='y', source=f2.pts, color="#E37222",line_width=5) plot.line(x='x', y='y', source=t_line, color="Black",line_width=5) plot.triangle(x='x', y='y', size = 'size', source= f1.tri,color="#808080", line_width=2) plot.triangle(x='x', y='y', size = 'size', source= f2.tri,color="#E37222", line_width=2) plot.axis.visible = False plot.outline_line_width = 7 plot.outline_line_alpha = 0.3 plot.outline_line_color = "Black" plot.title.text_color = "black" plot.title.text_font_style = "bold" plot.title.align = "center" labels1 = LabelSet(x='x', y='y', text='name', level='glyph', x_offset=0, y_offset=0, source=f1.label, render_mode='canvas') labels2 = LabelSet(x='x', y='y', text='name', level='glyph', x_offset=0, y_offset=0, source=f2.label, render_mode='canvas') #P arrow: p1_arrow_glyph = Arrow(end=NormalHead(line_color="#0065BD",line_width= 4, size=10), x_start='xS', y_start='yS', x_end='xE', y_end='yE',line_width= "lW", source=f1.arrow_source,line_color="#0065BD") p2_arrow_glyph = Arrow(end=NormalHead(line_color="#E37222",line_width= 4, size=10),
def make_axis(axis, size, factors, dim, flip=False, rotation=0, label_size=None, tick_size=None, axis_height=35): factors = list(map(dim.pprint_value, factors)) nchars = np.max([len(f) for f in factors]) ranges = FactorRange(factors=factors) ranges2 = Range1d(start=0, end=1) axis_label = dim_axis_label(dim) reset = "range.setv({start: 0, end: range.factors.length})" ranges.callback = CustomJS(args=dict(range=ranges), code=reset) axis_props = {} if label_size: axis_props['axis_label_text_font_size'] = value(label_size) if tick_size: axis_props['major_label_text_font_size'] = value(tick_size) tick_px = font_size_to_pixels(tick_size) if tick_px is None: tick_px = 8 label_px = font_size_to_pixels(label_size) if label_px is None: label_px = 10 rotation = np.radians(rotation) if axis == 'x': align = 'center' # Adjust height to compensate for label rotation height = int(axis_height + np.abs(np.sin(rotation)) * ((nchars*tick_px)*0.82)) + tick_px + label_px opts = dict(x_axis_type='auto', x_axis_label=axis_label, x_range=ranges, y_range=ranges2, plot_height=height, plot_width=size) else: # Adjust width to compensate for label rotation align = 'left' if flip else 'right' width = int(axis_height + np.abs(np.cos(rotation)) * ((nchars*tick_px)*0.82)) + tick_px + label_px opts = dict(y_axis_label=axis_label, x_range=ranges2, y_range=ranges, plot_width=width, plot_height=size) p = Figure(toolbar_location=None, tools=[], **opts) p.outline_line_alpha = 0 p.grid.grid_line_alpha = 0 if axis == 'x': p.yaxis.visible = False axis = p.xaxis[0] if flip: p.above = p.below p.below = [] p.xaxis[:] = p.above else: p.xaxis.visible = False axis = p.yaxis[0] if flip: p.right = p.left p.left = [] p.yaxis[:] = p.right axis.major_label_orientation = rotation axis.major_label_text_align = align axis.major_label_text_baseline = 'middle' axis.update(**axis_props) return p