不断增长的 Bokeh 嵌入源文件
Ever-growing Bokeh's embed source files
每次我制作 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.11.1
开始,您需要在某些情况下显式调用 reset_output
:
from bokeh.io import reset_output
reset_output()
我建议在 my_plot
函数的顶部调用它。
每次我制作 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.11.1
开始,您需要在某些情况下显式调用 reset_output
:
from bokeh.io import reset_output
reset_output()
我建议在 my_plot
函数的顶部调用它。