Python figure crashing and is unresponsive
<p>I'm trying to make a script where it'll go to each point and save a figure of the plot if the point is good or not. But the figure is just unresponsive/blank. Any ideas?</p>

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

A = range(-3, 3, 1)

for moving in range(len(A)):
    parsedFile = 'TEST/data_%d' % (moving)

    plt.figure(1)
    plt.plot(A)
    plt.plot(A[moving],"rx")

plt.show(block=False)
plotChoice = raw_input("Is this a good value? (y/n): ")

if plotChoice == 'y':
    plt.savefig(parsedFile + '.jpg', pdi=1000)
    plt.clf()
    plt.close()
else:
    plt.clf()
    plt.close()
</code></pre>

<p>Ran using PyCharm</p>

<p>In non-interactive mode <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.show" rel="nofollow">plt.show()</a> will block until the figure is closed. The <code>block</code> argument is experimental according to the documentation, and it seems to me that it won't work in your case. Well, at least it doesn't work for me.</p>

<p>To interact with the user of the plot you can use a <a href="http://matplotlib.org/api/widgets_api.html#matplotlib.widgets.Button" rel="nofollow">Button</a> widget. Two buttons 'Yes' and 'No' can be placed directly to the plot. Here you can find an example: <a href="http://matplotlib.org/examples/widgets/buttons.html" rel="nofollow">http://matplotlib.org/examples/widgets/buttons.html</a></p>

<p>Button placement is not straightforward, so to simplifiy things a little bit I used plot title for the question and added buttons alongside. May seem ugly, feel free to adjust to your needs:</p>

<pre><code>import matplotlib.pyplot as plt
from matplotlib.widgets import Button

ax = plt.subplot()
plt.title('Is this a good value?')

A = range(-3, 3, 1)

for moving in range(len(A)):
    parsedFile = 'TEST/data_%d' % moving

    ax.plot(A)
    ax.plot(A[moving], 'rx')

def yes(event):
    plt.savefig(parsedFile + '.jpg', pdi=1000)
    plt.clf()
    plt.close()

def no(event):
    plt.clf()
    plt.close()

yes_axes = plt.axes([0.69, 0.91, 0.1, 0.075])
yes_button = Button(yes_axes, 'Yes')
yes_button.on_clicked(yes)

no_axes = plt.axes([0.80, 0.91, 0.1, 0.075])
no_button = Button(no_axes, 'No')
no_button.on_clicked(no)

plt.show()
</code></pre>

python debugging figure