44# -----------------------------------------------------------------------------
55import matplotlib
66import numpy as np
7- matplotlib .use ('TkAgg' )
8- matplotlib .rcParams ['toolbar' ] = 'None'
7+ matplotlib .use ('TkAgg' ) # Required on OSX for animation
98import matplotlib .pyplot as plt
109from matplotlib .animation import FuncAnimation
1110
1211
1312# Create new figure
1413fig = plt .figure (figsize = (7 ,7 ))
15- fig .patch .set_facecolor ('white' )
1614ax = fig .add_axes ([0 ,0 ,1 ,1 ], frameon = False , aspect = 1 )
1715
1816# Create rain data
2321
2422# Scatter plot is used to animate rain drops
2523scat = ax .scatter (P ['position' ][:,0 ], P ['position' ][:,1 ], P ['size' ], lw = 0.5 ,
26- animated = True , edgecolors = P ['color' ], facecolors = 'None ' )
24+ animated = True , edgecolors = P ['color' ], facecolors = 'none ' )
2725ax .set_xlim (0 ,1 ), ax .set_xticks ([])
2826ax .set_ylim (0 ,1 ), ax .set_yticks ([])
2927
@@ -32,22 +30,23 @@ def update(frame):
3230 i = frame % len (P )
3331
3432 # Make all colors more transparent
35- P ['color' ][:,3 ] = np .maximum (0 , P ['color' ][:,3 ] - 1.0 / len (P ))
33+ P ['color' ][:,3 ] -= 1.0 / len (P )
34+ P ['color' ][:,3 ] = np .clip (P ['color' ][:,3 ], 0 , 1 )
3635
3736 # Make all circles bigger
3837 P ['size' ] += P ['growth' ]
3938
4039 # Pick a new position for oldest rain drop
41- P ['position' ][i ] = np .random .uniform (0 ,1 , 2 )
40+ P ['position' ][i ] = np .random .uniform (0 , 1 , 2 )
4241
4342 # Reset size
44- P ['size' ][i ] = 5
43+ P ['size' ][i ] = 5
4544
4645 # Reset color
47- P ['color' ][i ] = 0 , 0 , 0 , 1
46+ P ['color' ][i ] = ( 0 , 0 , 0 , 1 )
4847
4948 # Choose a random growth factor
50- P ['growth' ][i ] = np .random .uniform (50 ,200 )
49+ P ['growth' ][i ] = np .random .uniform (50 , 200 )
5150
5251 # Update scatter plot
5352 scat .set_edgecolors (P ['color' ])
0 commit comments