我可以在整个 jupyter notebook 上设置散景图大小吗

Can I set the bokeh figure size across an entire jupyter notebook

将 Matplotlib 与 Jupyter notebook 结合使用,我可以使用 notebook 指令设置笔记本中所有 matplotlib 图形的图形大小:

pylab.rcParams['figure.figsize'] = (14, 14)

bokeh有类似的说明吗?我看过并且只找到了对 figure 函数本身设置图形大小的能力的引用:

p = bokeh.plotting.figure(x, y,plot_width=400, plot_height=400)

但这意味着我必须为每个绘图等编程大小。我只是想知道目前 bokeh 中是否存在此功能。

确实有 built-in 设置默认图表大小的方法。

from bokeh.charts import defaults

defaults.width = 450
defaults.height = 350

这应该为整个笔记本设定标准。

更新

bokeh.charts 子包已在 bokeh 0.12.10 的当前版本中删除。这个子包应该移到另一个 bkcharts 包,但显然 bkcharts 不再维护。如果你使用上面的代码,如果 bokeh 版本大于 0.12.9,你将得到一个错误。

另一种方法是创建一个全局变量,命名为:

width = 450
height = 350

然后你就可以在你的绘图中引用这些值了。所以

from bokeh.plotting import figure
p = figure(plot_width=width, plot_height=height)

当然,您必须为笔记本中的每个图包含此说明。