python - Matplotlib plot only updates when windows is closed? -
i wrote following script display simple sine curve update ad infinitum:
#!/usr/bin/env python import seaborn sns import matplotlib.pyplot plt import matplotlib.animation animation import numpy np math import sin n = 0 =[] ns = [] def animate(i): as.append(sin(n)) ns.append(n) ax1.plot(np.array(ns),np.array(as)) while true: fig1 = plt.figure() ax1 = fig1.add_subplot(1,1,1) ani1 = animation.funcanimation(fig1, animate, interval=1) n = n + 0.05 plt.show()
however line updates (as in changes shape @ all) when try close window, can't find fix - how done? many in advance.
you have change n
inside animate
add different point - add same point don't see difference. try print(ns)
inside animate
in code.
import matplotlib.pyplot plt import matplotlib.animation animation math import sin n = 0 = [] ns = [] # ----- def animate(i): global n ns.append(n) as.append(sin(n)) ax1.plot(ns, as) n += 0.05 # ----- fig1 = plt.figure() ax1 = fig1.add_subplot(1,1,1) ani1 = animation.funcanimation(fig1, animate, interval=1) plt.show()
btw: can use i
def animate(i): n = 0.05 * ns.append(n) as.append(sin(n)) ax1.plot(ns, as)
Comments
Post a Comment