Python 重绘时Bokeh绘图失败
我正在IPython/Jupyter笔记本中运行从顶部答案到的代码。第一次运行时,它会正确显示: 如果我在再次运行单元格或在另一个单元格中运行相同代码时,更改任何参数,无论该参数多么无关紧要(例如,将单引号更改为双引号),都会出现以下情况: 它看起来像是在递归地将所需的2x1子地块网格放入一个新的2x1子地块网格中。我尝试添加Python 重绘时Bokeh绘图失败,python,bokeh,Python,Bokeh,我正在IPython/Jupyter笔记本中运行从顶部答案到的代码。第一次运行时,它会正确显示: 如果我在再次运行单元格或在另一个单元格中运行相同代码时,更改任何参数,无论该参数多么无关紧要(例如,将单引号更改为双引号),都会出现以下情况: 它看起来像是在递归地将所需的2x1子地块网格放入一个新的2x1子地块网格中。我尝试添加bk\u plotting.reset\u output(),但没有效果 这是手机代码: import numpy as np import bokeh.plottin
bk\u plotting.reset\u 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)
在这样的报告中指定版本很重要。这个bug在()中被注意到,在0.8.2版本之前,有一个修复程序记录在案。我无法用上面的代码在干净的Bokeh0.8.2环境(python3、jupiter/iPython3.10、OSX+safari)中重现这个问题。如果您仍然可以使用Bokeh>=0.8.2重现此问题,请在上提交一份错误报告,其中包含尽可能多的版本、平台等信息 就我而言,故障排除非常糟糕,你完全正确,我使用的是Bokeh0.8.1。升级解决了问题。太好了,很高兴听到这个消息!