为什么savefig和plot命令必须位于IPython Notebook的同一单元格中? [英] Why does savefig and plot commands have to be in the same cell in an IPython notebook?

查看:76
本文介绍了为什么savefig和plot命令必须位于IPython Notebook的同一单元格中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从IPython笔记本中导出一些图.搜索我发现此问题,并且可以进行排序问题.正如答案中指出的那样,我必须在与plot命令相同的单元格中调用savefig.

I was trying to export some plots from a IPython notebook. Searching I've found this question and could sort the issue. As it's noted in the answer, I had to call savefig in the same cell as the plot commands.

我的问题是,为什么这些呼叫必须在同一单元格中?我的笔记本服务器以--pylab=inline模式启动.如果不是内联,则可以很好地导出绘图.

My question is, why do those calls must be in the same cell? My notebook server was started in --pylab=inline mode. If it's not inline the plot are exported just fine.

推荐答案

我认为您正在从

I think you are seeing the behavior from this part of IPython's code base:

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')

显示打开的图形后,所有打开的图都被关闭.

After displaying the open figure all open plots are closed.

这篇关于为什么savefig和plot命令必须位于IPython Notebook的同一单元格中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆