我试着从一个IPython笔记本上导出一些图。搜索我找到了this question并可以解决问题。正如答案中指出的,我必须在savefig命令所在的单元格中调用plot
我的问题是,为什么这些电话必须在同一个手机里?我的笔记本服务器是在--pylab=inline模式下启动的。如果它不是内联的,绘图就可以很好地导出。

最佳答案

我想您是从part的代码库中看到的行为:

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

显示打开的图形后,所有打开的绘图都将关闭。

关于python - 为什么savefig和plot命令必须位于IPython Notebook的同一单元中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28859965/

10-12 21:10