当前位置: 首页>>代码示例>>Python>>正文


Python models.Legend方法代码示例

本文整理汇总了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) 
开发者ID:mars-project,项目名称:mars,代码行数:46,代码来源:task_pages.py

示例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 
开发者ID:timkpaine,项目名称:lantern,代码行数:47,代码来源:plot_bokeh.py


注:本文中的bokeh.models.Legend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。