8000 [DOC]: Add simple animation scatter plot to the example documentation… · matplotlib/matplotlib@1ade85c · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ade85c

Browse files
authored
[DOC]: Add simple animation scatter plot to the example documentation (#24096)
* add simple animation scatter plot * change title to Animated Scatter Saved as Gif * change title to sentence case
1 parent 30fbb45 commit 1ade85c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/animation/simple_scatter.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
=============================
3+
Animated scatter saved as GIF
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 gif
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)
0