Skip to content

Commit dde1897

Browse files
committed
add simple animation scatter plot
1 parent 76a5711 commit dde1897

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/animation/simple_scatter.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
======================
3+
Animated scatter plot
4+
======================
5+
6+
"""
7+
import numpy as np
8+
import matplotlib.pyplot as plt
9+
import matplotlib.animation as animation
10+
11+
fig, ax = plt.subplots()
12+
ax.set_xlim([0, 10])
13+
14+
scat = ax.scatter(1, 0)
15+
x = np.linspace(0, 10)
16+
17+
18+
def animate(i):
19+
scat.set_offsets((x[i], 0))
20+
return scat,
21+
22+
ani = animation.FuncAnimation(fig, animate, repeat=True,
23+
frames=len(x) - 1, interval=50)
24+
25+
# To save the animation using Pillow as a gifs
26+
# writer = animation.PillowWriter(fps=15,
27+
# metadata=dict(artist='Me'),
28+
# bitrate=1800)
29+
# ani.save('scatter.gif', writer=writer)
30+
31+
plt.show()

0 commit comments

Comments
 (0)