Why does my plot not disappear on exit in ipython mode?
<p>I'm showing some plots using <code>matplotlib</code> in the <code>ipython</code> prompt. When closing the plot window it does not disappear but gets "stuck" in the background and does not respond to user actions. You can try it out yourself with the following code: </p>

<pre><code># test.py
import matplotlib.pyplot as plt

def f(): 
    plt.plot([1, 2, 3], [4, 3, 5])
    plt.show()
</code></pre>

<p>and in the prompt</p>

<pre><code>pingul $ ipython
Python 3.5.2 (default, Jun 27 2016, 03:10:38) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.

In [1]: import test
In [2]: test.f()
### Trying to close it now doesn't work
</code></pre>

<p>Is this a bug, or can I fix it somehow?</p>

<p>Running the same code with the normal python prompt works as expected.</p>

<p>Try running <code>%matplotlib</code> before plotting, so that IPython integrates with the GUI event loop showing the plots.</p>

<p>This shouldn't be necessary once matplotlib 2.0 is released, because it has some code to detect when it's running inside IPython.</p>

python matplotlib ipython