9
9
10
10
import matplotlib .animation as animation
11
11
12
- # Constants
13
- decades = np .arange (1940 , 2020 , 10 )
14
- initial_widgets = 10000 # Rough estimate of the no. of widgets in the 1950s
15
-
16
- # Generate rough growth data
17
- growth_rate = np .random .uniform (1.02 , 3.10 , size = len (decades ))
18
- widgets_data = np .cumprod (growth_rate ) * initial_widgets
19
-
20
- # Set up the initial plot
21
- fig , ax = plt .subplots ()
22
- ax .set_xlim (1940 , 2020 )
23
- ax .set_ylim (0 , max (widgets_data ) + 100000 )
24
- line , = ax .plot ([], [])
25
- ax .set_xlabel ('Decade' )
26
- ax .set_ylabel ('Number of Widgets' )
27
-
28
- # Text annotation to display the current decade
29
- text = ax .text (0.5 , 0.85 , '' , transform = ax .transAxes ,
30
- fontsize = 12 , ha = 'center' , va = 'center' )
31
-
32
12
33
13
def update (frame , line , text , decades , widgets_data ):
34
14
# Parameters:
@@ -51,6 +31,27 @@ def update(frame, line, text, decades, widgets_data):
51
31
return line , text
52
32
53
33
# Set up the animation
34
+
35
+ # Constants
36
+ decades = np .arange (1940 , 2020 , 10 )
37
+ initial_widgets = 10000 # Rough estimate of the no. of widgets in the 1950s
38
+
39
+ # Generate rough growth data
40
+ growth_rate = np .random .uniform (1.02 , 3.10 , size = len (decades ))
41
+ widgets_data = np .cumprod (growth_rate ) * initial_widgets
42
+
43
+ # Set up the initial plot
44
+ fig , ax = plt .subplots ()
45
+ ax .set_xlim (1940 , 2020 )
46
+ ax .set_ylim (0 , max (widgets_data ) + 100000 )
47
+ line , = ax .plot ([], [])
48
+ ax .set_xlabel ('Decade' )
49
+ ax .set_ylabel ('Number of Widgets' )
50
+
51
+ # Text annotation to display the current decade
52
+ text = ax .text (0.5 , 0.85 , '' , transform = ax .transAxes ,
53
+ fontsize = 12 , ha = 'center' , va = 'center' )
54
+
54
55
ani = animation .FuncAnimation (
55
56
fig , # Figure to update
56
57
functools .partial (update , line = line , text = text , decades = decades , widgets_data = widgets_data ),
0 commit comments