我试图从 IPython 笔记本中导出一些图。搜索我发现这个问题 https://stackoverflow.com/questions/13642528/how-to-export-figures-to-files-from-ipython-notebook并可以解决这个问题。正如答案中所指出的,我不得不打电话savefig
在同一个单元格中plot
命令。
我的问题是,为什么这些呼叫必须在同一个单元格中?我的笔记本服务器启动于--pylab=inline
模式。如果它不是内联的,则绘图可以正常导出。
我认为你正在看到这种行为part https://github.com/ipython/ipython/blob/86c4d270e87b2a8f63f19016b57f846ab6063d06/IPython/kernel/zmq/pylab/backend_inline.py#L18-38 of IPython
的代码库:
def show(close=None):
"""Show all figures as SVG/PNG payloads sent to the IPython clients.
Parameters
----------
close : bool, optional
If true, a ``plt.close('all')`` call is automatically issued after
sending all the figures. If this is set, the figures will entirely
removed from the internal list of figures.
"""
if close is None:
close = InlineBackend.instance().close_figures
try:
for figure_manager in Gcf.get_all_fig_managers():
display(figure_manager.canvas.figure)
finally:
show._to_draw = []
# only call close('all') if any to close
# close triggers gc.collect, which can be slow
if close and Gcf.get_all_fig_managers():
matplotlib.pyplot.close('all')
显示开放图后,所有开放图都将关闭。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)