【问题标题】:python bokeh plotting package does not cache plots in jupyter notebookpython bokeh 绘图包不会在 jupyter notebook 中缓存绘图
【发布时间】:2017-05-03 02:51:12
【问题描述】:

在使用 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)

运行这个情节就可以了。但是当我保存笔记本,关闭它,然后重新打开它时,情节就不会再出现了。

其他人也有这个问题。

【问题讨论】:

    标签: python caching plot bokeh


    【解决方案1】:

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

    所以我基本上必须将初始化单元的导入放在笔记本的最开始。只有这样,图像的缓存才起作用。有趣的问题。

    【讨论】:

      猜你喜欢
      • 2016-10-10
      • 2017-10-03
      • 2020-02-01
      • 2017-05-11
      • 1970-01-01
      • 2019-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多