def generate_box_plot(sdf, colors): """ The colors were hacked in here! If the columns are not as in the order below in the final output, the colors will be wrong! """ from bokeh.charts import BoxPlot from bokeh.charts import color box_colors = [colors["HGST"], colors["Hitachi"], colors["Seagate"], colors["Toshiba"], colors["Western Digital"]] #palette = box_colors #print(box_colors) plot = BoxPlot(sdf, values='failure_rate', label='manufacturer', title="Failure Rate by Manufacturer", outliers=False, color=color(columns=['manufacturer'], palette=box_colors), legend=False, tools=None) plot.yaxis.axis_label = "Failure Rate" plot.xaxis.axis_line_width = 2 plot.yaxis.axis_line_width = 2 plot.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" plot.y_range = Range1d(0, 15) plot.ygrid.grid_line_color = None plot.toolbar.logo = None plot.outline_line_width = 0 plot.outline_line_color = "white" return plot
def _create_boxplot(self): print("boxplot") ys = self.df[self.w_y.value].values x_title = self.w_x.value.title() y_title = self.w_y.value.title() kw = dict() if self.w_y.value not in self.discrete: min_y = np.min(ys) max_y = np.max(ys) pad_y = (max_y - min_y) * 0.05 kw['y_range'] = Range1d(min_y - pad_y, max_y + pad_y) kw['title'] = "%s vs %s (boxplot)" % (x_title, y_title) p = BoxPlot(self.df, values=self.w_y.value, label=self.w_x.value, color=self.w_color.value, whisker_color=self.w_whisker.value, plot_height=600, plot_width=800, legend=False, tools='pan,box_zoom,reset', **kw) if 'y_range' in kw: p.y_range = kw['y_range'] return p
def cones_bokeh(self, windows=[30, 60, 90, 120], quantiles=[0.25, 0.75]): """Plots volatility cones Parameters ---------- windows : [int, int, ...] List of rolling windows for which to calculate the estimator cones quantiles : [lower, upper] List of lower and upper quantiles for which to plot the cones """ top_q, median, bottom_q, realized, min, max, f, data = self.cones_prepare_data( windows, quantiles) colors_list = ['orange', 'blue', 'pink', 'black', 'red', 'green'] methods_list = [ 'x', 'diamond', 'x', 'square', 'inverted_triangle', 'inverted_triangle' ] line_dash_list = [ 'dotted', 'dotdash', 'dotted', 'solid', 'dashed', 'dashed' ] xs = [windows, windows, windows, windows, windows, windows] ys = [top_q, median, bottom_q, realized, min, max] legends_list = [ str(int(quantiles[1] * 100)) + " Prctl", 'Median', str(int(quantiles[0] * 100)) + " Prctl", 'Realized', 'Min', 'Max' ] title = self._estimator + ' (' + self._symbol + ', daily from ' + self._last_date + ' days back ' + str( self._num_days_back) + ')' p = figure(title=title, plot_width=700, plot_height=500, toolbar_sticky=False, x_axis_label="Days", y_axis_label="Volatility", toolbar_location="below") legend_items = [] for (colr, leg, x, y, method, line_dash) in zip(colors_list, legends_list, xs, ys, methods_list, line_dash_list): # call dynamically the method to plot line, circle etc... renderers = [] if method: renderers.append(getattr(p, method)(x, y, color=colr, size=4)) renderers.append(p.line(x, y, color=colr, line_dash=line_dash)) legend_items.append((leg, renderers)) # doesnt work: legend = Legend(location=(0, -30), items=legend_items) legend = Legend(location=(0, -30), items=legend_items) p.add_layout(legend, 'right') from bokeh.charts import BoxPlot df = pandas.DataFrame({"data": data[0], "group": 0}) df = df.append(pandas.DataFrame({"data": data[1], "group": 1})) df = df.append(pandas.DataFrame({"data": data[2], "group": 2})) df = df.append(pandas.DataFrame({"data": data[3], "group": 3})) p2 = BoxPlot(df, values='data', label='group', title="Boxplot Summary (" + self._last_date + ") (" + self._symbol + ")", toolbar_location="below", legend="bottom_right", plot_width=600, plot_height=400, toolbar_sticky=False) from bokeh.models.ranges import DataRange1d p2.y_range = DataRange1d(np.min(df['data'] - 0.01), np.max(df['data'] + 0.01)) layout1 = layout([[p, p2]]) script, div = components(layout1) save_graph_to_db(script, div, self._symbol, self._expiry, self._last_date, self._num_days_back, self._resample, self._estimator, name="VOLEST") return layout1