gpt4 book ai didi

python - 重绘时 Bokeh 图失败

转载 作者:太空宇宙 更新时间:2023-11-03 17:44:37 28 4
gpt4 key购买 nike

我正在运行 this question 的最佳答案中的代码在 IPython/Jupyter 笔记本中。我第一次运行它时,它显示正确:

enter image description here

如果我更改任何参数,无论多么无关紧要(例如,将单引号更改为双引号),当我再次运行该单元格时,或者当我在另一个单元格中运行相同的代码时,都会出现以下内容:

enter image description here

看起来它递归地将所需的 2x1 子图网格放入新的 2x1 子图网格中。我尝试添加 bk_plotting.reset_output(),但没有效果。

这是单元格代码:

import numpy as np
import bokeh.plotting as bk_plotting
import bokeh.models as bk_models

# for the ipython notebook
bk_plotting.output_notebook()

# a random dataset
data = bk_models.ColumnDataSource(data=dict(x=np.arange(10),
y1=np.random.randn(10),
y2=np.random.randn(10)))

# defining the range (I tried with start and end instead of sources and couldn't make it work)
x_range = bk_models.DataRange1d(sources=[data.columns('x')])
y_range = bk_models.DataRange1d(sources=[data.columns('y1', 'y2')])

# create the first plot, and add a the line plot of the column y1
p1 = bk_models.Plot(x_range=x_range,
y_range=y_range,
title="",
min_border=2,
plot_width=250,
plot_height=250)
p1.add_glyph(data,
bk_models.glyphs.Line(x='x',
y='y1',
line_color='black',
line_width=2))

# add the axes
xaxis = bk_models.LinearAxis()
p1.add_layout(xaxis, 'below')
yaxis = bk_models.LinearAxis()
p1.add_layout(yaxis, 'left')

# add the grid
p1.add_layout(bk_models.Grid(dimension=1, ticker=xaxis.ticker))
p1.add_layout(bk_models.Grid(dimension=0, ticker=yaxis.ticker))

# add the tools
p1.add_tools(bk_models.PreviewSaveTool())

# create the second plot, and add a the line plot of the column y2
p2 = bk_models.Plot(x_range=x_range,
y_range=y_range,
title="",
min_border=2,
plot_width=250,
plot_height=250)
p2.add_glyph(data,
bk_models.glyphs.Line(x='x',
y='y2',
line_color='black',
line_width=2))



# add the x axis
xaxis = bk_models.LinearAxis()
p2.add_layout(xaxis, 'below')

# add the grid
p2.add_layout(bk_models.Grid(dimension=1, ticker=xaxis.ticker))
p2.add_layout(bk_models.Grid(dimension=0, ticker=yaxis.ticker))

# add the tools again (it's only displayed if added to each chart)
p2.add_tools(bk_models.PreviewSaveTool())

# display both
gp = bk_plotting.GridPlot(children=[[p1, p2]])
bk_plotting.show(gp)

最佳答案

在此类报告中指定版本非常重要。此错误已在 this GitHub issue 中记录。 ( detailed comment ),修复记录为在 this Pull Request 中已到位0.8.2 版本之前。我无法使用上面的代码在干净的 Bokeh 0.8.2 conda 环境(python3、jupiter/ipython 3.10、OSX+safari)中重现该问题。如果您在 Bokeh >= 0.8.2 时仍然重现此问题,请在 Bokeh issue tracker 上提交错误报告。尽可能多地提供版本、平台等信息。

关于python - 重绘时 Bokeh 图失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002213/

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