def figure(filename, show=False, save=False, **kwargs):
"""Context manager for using :class:`bokeh.plotting.figure`.
Args:
filename (str):
show (bool):
save (bool):
Yields:
Figure:
Examples:
>>> with figure('figure.html', show=True, save=False) as p:
>>> p.patch(...)
"""
base, ext = os.path.splitext(filename)
_, name = os.path.split(base)
if ext != '.html':
filename += '.html'
bokeh.io.output_file(filename, name)
fig = bokeh.plotting.Figure(**kwargs)
yield fig
if show:
bokeh.io.show(fig)
if save:
bokeh.io.save(fig)
评论列表
文章目录