简体   繁体   English

如何加快在 Bokeh 中创建的图的页面加载速度?

[英]How can I speed up the page load of plots created in Bokeh?

After I run my code, the page opens up and for 13 seconds a blank page shows up, and after that, the expected plots.运行我的代码后,页面打开并显示空白页面 13 秒,然后是预期的图。

Is there a way to speed this up?有没有办法加快这个速度? (13 seconds, user wise is sadly too long) (13 秒,用户明智太长了)

The code produces 44 plots, in two columns(2n loop), differ by parameter (1st loop) and then differ by tool name (3 rd loop)该代码生成 44 个图,分为两列(2n 循环),因参数而异(第一个循环),然后因工具名称而异(第三个循环)

Also if bokeh, isnt the right tool for this, would happily open to hear a way to plot interactive plots, preferably with python此外,如果散景不是正确的工具,将很乐意听到一种绘制交互式绘图的方法,最好是使用 python

This is the code:这是代码:

dateparse = lambda x: pd.datetime.strptime(x, '%Y-%m-%dT%H:%M:%S')

df = pd.read_csv("LUSU.csv",parse_dates=['PM_START_DATE'], date_parser=dateparse)

df.head()
print("time elapsed: {:.2f}s".format(time.time() - start_time))
x = df['PM_START_DATE']
y = df['TASK_VALUE']
tool=df['ENTITY']
tool_list=df['ENTITY'].unique()
param_list=df['PARAMETER'].unique()
#
print("time elapsed: {:.2f}s".format(time.time() - start_time))
colors = itertools.cycle(Spectral11)
output_file('LUSU.html', mode="cdn")
for i in range(0,44,2):
    row = []
    for _ in range(2):
        p = figure(title=param_list[i], x_axis_label='date', y_axis_label='chart value', x_axis_type="datetime", toolbar_location="below")
        for j in range(len(tool_list)):
            df1=((df['PARAMETER']==param_list[i] )& (df['ENTITY']==tool_list[j] ))
            source = ColumnDataSource(data=dict(x=x.loc[df1], y=y.loc[df1], tool=tool.loc[df1]))
            p.line(x='x', y='y',legend='tool', source=source)
            p.scatter(x='x', y='y',legend='tool',size=10,color=next(colors), source=source)
        p.add_tools(HoverTool(tooltips=[("Entity", "@tool"), ("Chart Value", "@y{%0.2f}"), ("Date", "@x{%F}")], formatters={"x": "datetime", "y": 'printf'}))
        #p.xaxis.formatter = DatetimeTickFormatter(days=["%m/%d/%Y"])
        p.legend.location = "top_right"
        p.legend.click_policy = "mute"
        row.append(p)
        i = i + 1
    grid.append(row)

fig=layout(grid)
reset_output()

show(fig)

You could try to use webGL to speed it up.您可以尝试使用 webGL 来加快速度。 This allows glyphs to render via the GPU.这允许字形通过 GPU 呈现。

figure(title=param_list[i], x_axis_label='date', y_axis_label='chart value', x_axis_type="datetime", toolbar_location="below", output_backend="webgl")

More information: https://docs.bokeh.org/en/latest/docs/user_guide/webgl.html .更多信息: https : //docs.bokeh.org/en/latest/docs/user_guide/webgl.html

Further reading about Bokeh performance issues with a lot of plots: https://github.com/bokeh/bokeh/issues/6294 .进一步阅读关于散景性能问题的大量图: https : //github.com/bokeh/bokeh/issues/6294

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM