I use the below code. This comes up with three different windows. I would like the plot to show up in the same window. Any ideas?
Thanks
-- ps: clarification. I would like to see the curve of y[0] vs x[0] first then it erased and see y[1] vs x[1] and then it erased and see y[2] vs x[2]. Right now it is showing all three with three different colors. See second chunk of code.
--
import numpy
from matplotlib import pyplot as plt
x = [1, 2, 3]
plt.ion() # turn on interactive mode, non-blocking `show`
for loop in range(0,3):
y = numpy.dot(x, loop)
plt.figure() # create a new figure
plt.plot(x,y) # plot the figure
plt.show() # show the figure, non-blocking
_ = input("Press [enter] to continue.") # wait for input from the
import numpy
import matplotlib.pyplot as plt
%matplotlib notebook
x = [[1, 2, 3], [4,5,6], [7,8,9]]
y = [[1,4,9], [16,25,36], [49,64,81]]
fig, ax = plt.subplots()
plt.ion()
plt.show()
for i in range(3):
ax.plot(x[i],y[i]) # plot the figure
plt.gcf().canvas.draw()
_ = input("Press [enter] to continue.") # wait for input from the
block=Falseinplt.show(). Second, you are creating a new figure every time you callplt.figure(). To add a new plot just useplt.plot()without refering to the figure. I am not sure about theinput(), but it is worth considering matplotlib events or widgets for triggering the plot update, as they still work withplt.show(). Lastly, to update the figure you can callplt.gcf().canvas.draw().