重绘时散景图失败

Bokeh plot fails when redrawn

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

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

它看起来像是在递归地将所需的 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), with a fix recorded as being in put in place in this Pull Request before the 0.8.2 release. I cannot reproduce the problem in a clean Bokeh 0.8.2 conda environent (python3, jupiter/ipython 3.10, OSX+safari) with the code above. If you can still reproduce this problem with Bokeh >= 0.8.2, please file a bug report on Bokeh issue tracker 中注明,其中包含尽可能多的版本、平台等信息。