Skip to content

Commit f4fe3e1

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

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 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 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy