Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # animated GIF: https://media.giphy.com/media/3og0IR8kl9YxONfB7y/giphy.gif
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- fig, ax = plt.subplots()
- x = np.arange(0, 2*np.pi, 0.1)
- px = np.arange(0, 2*np.pi, (2*np.pi-0.1)/4)
- #q = len(x)//4
- #px = np.array([x[q*0], x[q*1], x[q*2], x[q*3], x[q*4]])
- line, = ax.plot(x, np.sin(x), 'red')
- points, = ax.plot(px, np.sin(px), 'go') # 'g' = green, 'o' = circles
- def animate(i):
- print(i)
- line.set_ydata(np.sin(x+i))
- points.set_ydata(np.sin(px+i))
- return line, points
- # interval=50 gives fps=20 (50ms*20 = 1000ms = 1second)
- ani = animation.FuncAnimation(fig, animate, x, interval=50, blit=True)
- # display animation - it doesn't stop - you have to close window
- plt.show()
- # save in file - it may need some time to render and save all frames
- ani.save('animation.gif', writer='imagemagick', fps=20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement