Matplotpib figure in a loop not responding
<p>Python 2.7.11, Win 7, x64, Numpy 1.10.4, matplotlib 1.5.1</p>

<p>I ran the following script from an iPython console after entering <code>%matplotlib qt</code> at the command line</p>

<pre><code>from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np

number = input("Number: ")
coords = np.array(np.random.randint(0, number, (number, 3)))

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(coords[:,0], coords[:,1], coords[:,2])
plt.show()
</code></pre>

<p>It plots a random scatter in 3D. So I thought it would be a trivial matter to just pop it into a while loop &amp; get a new figure on each iteration.</p>

<pre><code>from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import numpy as np

s = True
while s:

    number = input("Number: ")
    coords = np.array(np.random.randint(0, number, (number, 3)))

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(coords[:,0], coords[:,1], coords[:,2])
    plt.show()
    cont = input("Continue? (y/n)")
    if cont == 'n':
        s = False
</code></pre>

<p>...but the figures are just blank &amp; unresponsive until I enter an input for <code>cont</code> then I get,</p>

<blockquote>
  <p>NameError: name 'y' is not defined</p>
</blockquote>

<p>...and the whole thing crashes.</p>

<p>So what am I missing here?</p>

<p>EDIT: Taking into account Aquatically challenged's answer below. The figures still hang until the loop is exited, then they are all plotted at the same time. Anybody know why the plots are not done within the loop?</p>

<p>I haven't replicated but when you input the <code>'y'</code> or <code>'n'</code>. try to put the single (or double quotes) are the <code>y</code> or <code>n</code></p>

<p>to input strings without quotes. Use <code>raw_input</code> instead of <code>input</code></p>

<p>as described here <a href="http://stackoverflow.com/questions/4960208/python-2-7-getting-user-input-and-manipulating-as-string-without-quotations">Python 2.7 getting user input and manipulating as string without quotations</a></p>

python numpy matplotlib