本文整理匯總了Python中bokeh.models.Legend方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Legend方法的具體用法?Python models.Legend怎麽用?Python models.Legend使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bokeh.models
的用法示例。
在下文中一共展示了models.Legend方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: task_progress_app
# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import Legend [as 別名]
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)
示例2: show
# 需要導入模塊: from bokeh import models [as 別名]
# 或者: from bokeh.models import Legend [as 別名]
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