matplotlib/matplotlib — pull request #3916 by matthew-brett (2014-12-12 19:25:58+00:00)
Title: RF: always close old figure windows

The plot directive first runs the specified code, then collects figures with::

fig_managers = _pylab_helpers.Gcf.get_all_fig_managers()

If you are using the "context" option, prior figures maybe generated from a
previous plot directive command, are still open, and therefore collected with
the new figure(s). The old figures will usually be earlier in the list, and
so, for something like this ReST block, you will always get the first
generated figure (``range(10)``) repeated in the second plot directive panel::

#######
A title
#######

.. plot::
:context:

import matplotlib.pyplot as plt
plt.plot(range(10))

Then some text.

.. plot::
:context:

plt.figure()
plt.plot(range(5), 'r')

This PR always closes previous figure windows before running the plot
directive code.

See email discussion thread starting here:

https://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg10816.html