반응형
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

bro's coding

matplotlib.animation 본문

[IT]/python.matplotlib

matplotlib.animation

givemebro 2020. 6. 8. 15:18
반응형
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

fig, ax=plt.subplots()
ax.set_xlim((0,2))
ax.set_ylim((-2,2))
ax.grid(True)

line,=ax.plot([],[],lw=2)

def init():
    line.set_data(([],[]))
    return (line,)

def animate(t):
    x=np.linspace(0,2,1000)
    y=np.sin(2*np.pi*(x-0.01*t))
    line.set_data(x,y)
    return (line,)

ani=animation.FuncAnimation(fig=fig,func=animate,init_func=init,interval=20,blit=True)
plt.show()

 

(움직이는 중임)

반응형
Comments