waitforbuttonpress() matplotlib possible bug
<p>Consider a refreshed figure inside a loop as per the following code:</p>

<pre><code>import matplotlib.pyplot as plt

def fun_example():

    plt.ion()
    for ite in range(3):
        x = np.linspace(-2,6,100)
        y = (ite+1)*x

        figura = plt.figure(1)
        plt.plot(x,y,'-b')
        plt.waitforbuttonpress()
        plt.close()
    #endfor ite

#enddef fun_example

if __name__ == '__main__':
    fun_example()
#endif main
</code></pre>

<p>The idea is to inspect the figure with the mouse (for example, during debugging use the zoom option in the toolbar of the figure), and once it is done, press a button to go on with the code. At least in my case (windows 7, python 3.4.4, spyder 3.0.0dev), if I intend to mouse click in the graph for zooming, the effect is the same than press-button. In other words <em>waitforbuttonpress()</em> returns <em>True</em>, and the figure is gone.</p>

<p>Any suggestion? might it be a bug? Thank all of you in advance.</p>

<p>As per <a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.waitforbuttonpress" rel="nofollow">the documentation</a>, <code>.waitforbuttonpress()</code> will return <code>True</code> if a key was pressed, and <code>False</code> if a mouse button was pressed. Therefore, what you want is probably something like this:</p>

<pre><code>while True:
    if plt.waitforbuttonpress():
        break
</code></pre>

python matplotlib figure