python bokeh绘图软件包不会在jupyter笔记本中缓存图



python中的bokeh绘图软件包遇到了令人沮丧的问题。因此,我有一个jupyter笔记本(笔记本版5.0.0(,其中有一些散景图。笔记本现在很大,因此加载确实需要一些时间。无论如何,当我使用Matplotlib时,笔记本中的图像将被缓存。这样一来,每次运行笔记本时,我都不需要重新运行它们。

Bokeh具有缓存图像的能力相同,但我似乎无法使图像缓存起作用。因此,对于一个非常简单的示例,如果我在笔记本中有以下代码:

from bokeh.resources import INLINE
import builtins
import os, sys
import time
import pyugend
import datetime
from IPython.lib import deepreload
builtins.reload = deepreload.reload
from ipywidgets import widgets
from IPython.display import display
from bokeh.io import show, output_notebook
from bokeh.layouts import gridplot
from bokeh.palettes import Viridis3
from bokeh.plotting import figure
from bokeh.charts import defaults
from bokeh import mpl
defaults.width = 700
defaults.height = 700
output_notebook(resources=INLINE)
#output_notebook()
#notebook_handle=True
%reload_ext autoreload
time.sleep(1)
from bokeh.sampledata.iris import flowers
colormap = {'setosa': 'red', 'versicolor': 'green', 'virginica': 'blue'}
colors = [colormap[x] for x in flowers['species']]
p = figure(title = "Iris Morphology")
p.xaxis.axis_label = 'Petal Length'
p.yaxis.axis_label = 'Petal Width'
p.circle(flowers["petal_length"], flowers["petal_width"],
         color=colors, fill_alpha=0.2, size=10)

show(p)

运行此图的工作正常。但是,当我保存笔记本,将其关闭并重新打开时,该情节不会再次出现。

其他任何人都有这个问题。

我找出了这个问题的答案。因此,问题在于Jupyter初始化单元格的扩展。我有代码可以在笔记本底部的初始化单元格中进行bokeh的导入。但是,当我出于某种原因这样做时,笔记本中较早的绘图单元格没有显示缓存的图像。

因此,我不得不基本上将初始化单元的导入到笔记本开始时。只有这样,图像的缓存才起作用。有趣的问题。

最新更新