Issue
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.
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.
Solution
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.
Answered By - cel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.