Issue
I am trying to plot some figures (matplotlib) in a for loop and plotting the result in a figure window. The figure window updates after every loop. However, the figure window is unresponsive or blank and does not show any plot until the loop is terminated. I am using a Spyder and Python 3.7.
Any suggestions?
Edit: Below is some sample code
import numpy as np
import matplotlib.pyplot as plt
import time
x = np.linspace(0,2*np.pi,100)
for amp in range(10):
print(amp)
y = amp*np.cos(x)
plt.figure(1)
plt.plot(x,y)
time.sleep(1)
Solution
Using plt.draw()
should do it. Try something like this
import numpy as np
import matplotlib.pyplot as plt
import time
plt.show()
x = np.linspace(0,2*np.pi,100)
for amp in range(10):
print(amp)
y = amp*np.cos(x)
plt.plot(x,y)
plt.draw()
plt.pause(0.001)
input("Press [enter] to continue.")
Answered By - Arsal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.