【发布时间】: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)
运行这个情节就可以了。但是当我保存笔记本,关闭它,然后重新打开它时,情节就不会再出现了。
其他人也有这个问题。
【问题讨论】: