Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72b7bed

Browse files
committed
Reduced figure size for smoother animation
1 parent 3228926 commit 72b7bed

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

examples/animation/rain.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@
1010
from matplotlib.animation import FuncAnimation
1111

1212

13-
fig = plt.figure(figsize=(8,8))
13+
# Create new figure
14+
fig = plt.figure(figsize=(7,7))
1415
fig.patch.set_facecolor('white')
1516
ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1)
1617

18+
# Create rain data
1719
P = np.zeros(50, dtype=[('position', float, 2),
1820
('size', float, 1),
1921
('growth', float, 1),
2022
('color', float, 4)])
23+
24+
# Scatter plot is used to animated rain drops
2125
scat = ax.scatter(P['position'][:,0], P['position'][:,1], P['size'], lw=0.5,
2226
animated=True, edgecolors = P['color'], facecolors='None')
2327
ax.set_xlim(0,1), ax.set_xticks([])
@@ -32,10 +36,13 @@ def update(frame):
3236
# Make all circles bigger
3337
P['size'] += P['growth']
3438

35-
# Pick new position for oldest rain drop
39+
# Pick a new position for oldest rain drop
3640
P['position'][i] = np.random.uniform(0,1,2)
41+
# Reset size
3742
P['size'][i] = 5
43+
# Reset color
3844
P['color'][i] = 0,0,0,1
45+
# Choose a random growth factor
3946
P['growth'][i] = np.random.uniform(50,200)
4047

4148
# Update scatter plots

0 commit comments

Comments
 (0)