Python bokeh.models.Legend() Examples
The following are 2
code examples of bokeh.models.Legend().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bokeh.models
, or try the search function
.
Example #1
Source File: task_pages.py From mars with Apache License 2.0 | 4 votes |
def task_progress_app(scheduler_ip, doc): session_id = to_str(doc.session_context.request.arguments.get('session_id')[0]) task_id = to_str(doc.session_context.request.arguments.get('task_id')[0]) web_api = MarsWebAPI(scheduler_ip) states = list(OperandState.__members__.values()) ops, stats, progress = web_api.get_task_detail(session_id, task_id) source = ColumnDataSource(stats) cols = list(stats)[1:] p = figure(y_range=ops, plot_height=500, plot_width=800, x_range=(0, 100), title="Total Progress: %0.2f%%" % progress) renderers = p.hbar_stack(cols, y='ops', height=0.9, color=_base_palette[0:len(states)], source=source) legend_items = [('\0' + s, [r]) for s, r in zip(cols, renderers)] legend = Legend(items=legend_items, location='bottom_right', orientation='horizontal', label_text_font_size='10px') p.add_layout(legend, 'below') p.ygrid.grid_line_color = None p.yaxis.major_tick_line_color = None p.yaxis.minor_tick_line_color = None p.axis.minor_tick_line_color = None p.outline_line_color = None doc.add_root(p) def _refresher(): try: _, new_stats, new_progress = web_api.get_task_detail(session_id, task_id) except ActorNotExist: # pragma: no cover doc.remove_periodic_callback(cb) p.title.text = "Graph not found, session may be stopped" return p.title.text = "Total Progress: %0.2f%%" % new_progress source.data = new_stats if new_progress >= 100.0: doc.remove_periodic_callback(cb) if progress < 100.0: cb = doc.add_periodic_callback(_refresher, 5000)
Example #2
Source File: plot_bokeh.py From lantern with Apache License 2.0 | 4 votes |
def show(self, title='', xlabel='', ylabel='', xaxis=True, yaxis=True, xticks=True, yticks=True, legend=True, grid=True, **kwargs): # self.figure.add_tools(*[HoverTool( # tooltips=[('x', '@x{%F}'), ('y', '@y')], # formatters={'x': 'datetime'}, # mode='vline' # ) for _ in data]) self.figure.outline_line_color = None # vline = Span(location=0, dimension='height', line_color='red', line_width=3) hline = Span(location=0, dimension='width', line_color='black', line_width=1) self.figure.renderers.append(hline) if xlabel: self.figure.xaxis.axis_label = kwargs.get('xlabel') if ylabel: self.figure.yaxis.axis_label = kwargs.get('ylabel') if title: self.figure.title.text = kwargs.get('title') if legend: self.figure.legend.location = (self.width + 10, self.height + 10) legend = Legend(items=self.legend, location=(10, 100)) legend.items = self.legend legend.click_policy = "mute" self.figure.add_layout(legend, 'right') else: self.figure.legend.location = None if not grid: self.figure.xgrid.grid_line_color = None self.figure.ygrid.grid_line_color = None # FIXME if not yaxis: for ax in self.figure.yaxis: ax.axis_line_color = 'white' if not xaxis: for ax in self.figure.xaxis: ax.axis_line_color = 'white' # Turn off labels: # self.figure.xaxis.major_label_text_font_size = '0pt' show(self.figure) return self.figure