gpt4 book ai didi

Python Bokeh : Plotting same chart multiple times in gridplot

转载 作者:行者123 更新时间:2023-11-28 19:14:50 25 4
gpt4 key购买 nike

我目前正在尝试获取不同日期数据图的概览。为了更好地了解数据,我想将相关的绘图并排绘制。这意味着我想在 gridplot 命令中多次使用同一个图。但是我注意到,当我多次使用同一个图表时,它只会在最终的 .html 文件中显示一次。我第一次尝试解决这个问题是对图表使用 copy.deepcopy,但这导致了以下错误:

RuntimeError: Cannot get a property value 'label' from a LineGlyph instance before HasProps.__init__

我的方法如下:

from bokeh.charts import Line, output_file, show, gridplot
import pandas as pd
output_file('test.html')
plots = []

df = pd.DataFrame([[1,2], [3,1], [2,2]])
print(df)
df.columns = ['x', 'y']
for i in range(10):
plots.append(Line(df, x='x', y='y', title='Forecast: ' + str(i),
plot_width=250, plot_height=250))

plot_matrix = []
for i in range(len(plots)-1, 2, -1):
plot_matrix.append([plots[i-3], plots[i-2], plots[i]])
p = gridplot(plot_matrix)
show(p)

结果是一个带有网格图的 html 页面,其中有很多缺失的图表。每个图表都准确显示一次(而不是所需的 3 次),这让我认为网格图不喜欢我多次使用同一个对象。一个明显的解决方案是简单地将每个图形创建 3 次作为不同的对象,我现在将这样做,但这不仅效率低下,而且在查看我的代码时还会伤害我的眼睛。我希望有人能为我的问题提供更优雅的解决方案。

编辑:使代码可运行

最佳答案

这是不可能的。 Bokeh 图(或一般的 Bokeh 对象)可能不会在布局中重复使用。

关于Python Bokeh : Plotting same chart multiple times in gridplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34920352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com