def _plot_bokeh(self, current_plot, show_legend=True): import bokeh.models as mdl import bokeh.plotting as bkh from bokeh.properties import value lst = [] row_lst = [] for plotter in self.plots: cur_plot = bkh.figure(title=plotter.title, plot_width=self.one_figsize[0] * self.BOKEH_RESIZE, plot_height=self.one_figsize[1] * self.BOKEH_RESIZE) if plotter.xlim is not None: cur_plot.x_range = mdl.Range1d(start=plotter.xlim[0], end=plotter.xlim[1]) if plotter.ylim is not None: cur_plot.y_range = mdl.Range1d(start=plotter.ylim[0], end=plotter.ylim[1]) cur_plot.title_text_font_size = value("{}pt".format(plotter.fontsize)) cur_plot.xaxis.axis_label = plotter.xlabel cur_plot.yaxis.axis_label = plotter.ylabel cur_plot.legend.orientation = 'top_right' cur_plot = plotter._plot_bokeh(cur_plot, show_legend=show_legend) if len(row_lst) >= self.columns: lst.append(row_lst) row_lst = [] row_lst.append(cur_plot) if len(row_lst) > 0: lst.append(row_lst) grid = mdl.GridPlot(children=lst) return grid
def plot_bokeh(self, xlim=None, ylim=None, title=None, figsize=None, xlabel=None, ylabel=None, fontsize=None, show_legend=True): """ Plot data using bokeh library. Use show() method for bokeh to see result. :param bool new_plot: create or not new figure :param xlim: x-axis range :param ylim: y-axis range :type xlim: None or tuple(x_min, x_max) :type ylim: None or tuple(y_min, y_max) :param title: title :type title: None or str :param figsize: figure size :type figsize: None or tuple(weight, height) :param xlabel: x-axis name :type xlabel: None or str :param ylabel: y-axis name :type ylabel: None or str :param fontsize: font size :type fontsize: None or int :param bool show_legend: show or not labels for plots """ global _COLOR_CYCLE_BOKEH import bokeh.plotting as bkh from bokeh.models import Range1d from bokeh.properties import value figsize = self.figsize if figsize is None else figsize xlabel = self.xlabel if xlabel is None else xlabel ylabel = self.ylabel if ylabel is None else ylabel title = self.title if title is None else title xlim = self.xlim if xlim is None else xlim ylim = self.ylim if ylim is None else ylim fontsize = self.fontsize if fontsize is None else fontsize self.fontsize_ = fontsize self.show_legend_ = show_legend figsize = (figsize[0] * self.BOKEH_RESIZE, figsize[1] * self.BOKEH_RESIZE) bkh.output_notebook() current_plot = bkh.figure(title=title, plot_width=figsize[0], plot_height=figsize[1]) _COLOR_CYCLE_BOKEH = itertools.cycle(COLOR_ARRAY_BOKEH) if xlim is not None: current_plot.x_range = Range1d(start=xlim[0], end=xlim[1]) if ylim is not None: current_plot.y_range = Range1d(start=ylim[0], end=ylim[1]) current_plot.title_text_font_size = value("{}pt".format(fontsize)) current_plot.xaxis.axis_label = xlabel current_plot.yaxis.axis_label = ylabel current_plot.legend.orientation = 'top_right' current_plot = self._plot_bokeh(current_plot, show_legend) bkh.show(current_plot)
plot_height=300, min_border=0, title="Hover and tap discontinuous patches.") patches_dis_data = pd.DataFrame( { 'xs': [[0, 49, 49, 0, NAN, 51, 89, 89, 51], [90, 100, 100, 90], [92, 98, 98, 92]], 'ys': [[0, 0, 80, 80, NAN, 0, 0, 90, 90], [0, 0, 100, 100], [20, 20, 90, 90]], 'value': ['I am one object split in two', 'I am wheat', 'I am steelblue'], 'fill_color': ['firebrick', 'wheat', 'steelblue'] }, ) plot_patches_dis = Plot(**PLOT_FORMATS) plot_patches_dis.add_glyph( ColumnDataSource(patches_dis_data), Patches( xs='xs', ys='ys', fill_color='fill_color', line_color=value('wheat'), )) plot_patches_dis.add_tools(HoverTool(tooltips='@value')) plot_patches_dis.add_tools(TapTool()) filename = '2376_hover_on_discontinuous_patches.html' output_file(filename, title='Discontinuous Patches', mode='relative-dev') save(plot_patches_dis) view(filename)
from bokeh.models import Plot, Range1d, ColumnDataSource, Patches, HoverTool, TapTool from bokeh.properties import value from bokeh.io import save, output_file PLOT_FORMATS = dict(x_range=Range1d(0,100), y_range=Range1d(0,100), plot_width=500, plot_height=300, min_border=0, title="Hover and tap discontinuous patches.") patches_dis_data = pd.DataFrame( { 'xs': [[0, 49, 49, 0, NAN, 51, 89, 89, 51], [90, 100, 100, 90], [92, 98, 98, 92]], 'ys': [[0, 0, 80, 80, NAN, 0, 0, 90, 90], [0, 0, 100, 100], [20, 20, 90, 90]], 'value': ['I am one object split in two', 'I am wheat', 'I am steelblue'], 'fill_color': ['firebrick', 'wheat', 'steelblue'] }, ) plot_patches_dis = Plot(**PLOT_FORMATS) plot_patches_dis.add_glyph( ColumnDataSource(patches_dis_data), Patches( xs='xs', ys='ys', fill_color='fill_color', line_color=value('wheat'), ) ) plot_patches_dis.add_tools(HoverTool(tooltips='@value')) plot_patches_dis.add_tools(TapTool()) filename = '2376_hover_on_discontinuous_patches.html' output_file(filename, title='Discontinuous Patches', mode='relative-dev') save(plot_patches_dis) view(filename)