Bokeh的嵌入源文件每次制作时都会变大(来自Jupyter Notebook)。我怎么能阻止这个?
代码:
from bokeh.plotting import figure, show
from bokeh.embed import components
from bokeh.io import output_notebook
output_notebook()
def my_plot(color):
p = figure(plot_width=400, plot_height=400)
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], color=color)
script, div = components(p)
with open('{}.html'.format(color),'w') as f:
f.write(script)
f.write(div)
show(p)
my_plot('red')
my_plot('blue')
my_plot('green')
my_plot('cyan')
my_plot('magenta')
my_plot('yellow')
结果:
Directory of C:\Users\TomV\Codes\misc
06/06/2016 15:43 <DIR> ..
06/06/2016 15:27 <DIR> .ipynb_checkpoints
06/06/2016 15:43 <DIR> .
06/06/2016 15:39 17,684 red.html
06/06/2016 15:40 23,366 blue.html
06/06/2016 15:40 29,049 green.html
06/06/2016 15:41 34,731 cyan.html
06/06/2016 15:41 40,416 magenta.html
06/06/2016 15:41 46,100 yellow.html
06/06/2016 15:43 246,485 Bokeh_embed_test.ipynb
7 File(s) 437,831 bytes
请勿进一步阅读。这只是为了安抚那些想让我添加细节的SO无头机器人。
答案 0 :(得分:2)
从版本0.11.1
开始,您需要在某些情况下显式调用reset_output
:
from bokeh.io import reset_output
reset_output()
我建议在my_plot
函数的顶部调用它。