Python 2.7.11, Win 7, x64, Numpy 1.10.4, matplotlib 1.5.1
I ran the following script from an iPython console after entering %matplotlib qt
at the command line
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()
It plots a random scatter in 3D. So I thought it would be a trivial matter to just pop it into a while loop & get a new figure on each iteration.
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
...but the figures are just blank & unresponsive until I enter an input for cont
then I get,
NameError: name 'y' is not defined
...and the whole thing crashes.
So what am I missing here?
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?