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>You should be a bit careful with using pyplot in ipython.  Especially <code>plt.show()</code> is blocking the ipython terminal.  You should use <code>fig.show()</code>, since it does not block ipython.  If you really want to use pyplot, one work-around is to use <code>plt.gcf().show()</code>, which will get the current figure (gcf=get current figure) and only show that figure.  However I would recommend creating the figure as <code>fig = plt.figure()</code> and then use <code>fig.show()</code>. </p>

<p>Please note that if you run it with python, you need <code>plt.show()</code>!  Otherwise the figure will show, and then close immediately! </p>

python matplotlib ipython