1
1
"""
2
2
==================================
3
- Parameterized Animation Functions
3
+ Parameterized animation function
4
4
==================================
5
- use FuncAnimation to show counts of widgets over the decades
5
+ use `~.Animation. FuncAnimation` to show counts of widgets over the decades
6
6
"""
7
7
8
8
import functools
@@ -19,7 +19,7 @@ def update(frame, line, text, decades, widgets_data):
19
19
# line (Line2D): The line object to update.
20
20
# text (Text): The text annotation object to update.
21
21
# decades (numpy.ndarray): Array of decades.
22
- # widgets_data (numpy.ndarray): Array of widgets' data.
22
+ # widgets_data (numpy.ndarray): Array of widgets data.
23
23
24
24
# Returns:
25
25
# tuple: Tuple containing the updated Line2D and Text objects.
@@ -45,16 +45,19 @@ def update(frame, line, text, decades, widgets_data):
45
45
46
46
# Set up the initial plot
47
47
fig , ax = plt .subplots ()
48
- ax . set_xlim ( 1940 , 2020 )
49
- ax . set_ylim ( 0 , max ( widgets_data ) + 100000 )
48
+
49
+ # line being animated
50
50
line , = ax .plot ([], [])
51
- ax .set_xlabel ('Decade' )
52
- ax .set_ylabel ('Number of Widgets' )
53
51
54
52
# Text annotation to display the current decade
55
53
text = ax .text (0.5 , 0.85 , '' , transform = ax .transAxes ,
56
54
fontsize = 12 , ha = 'center' , va = 'center' )
57
55
56
+ ax .set (xlabel = 'Decade' , ylabel = 'Number of Widgets' ,
57
+ xlim = (1940 , 2020 ),
58
+ ylim = (0 , max (widgets_data ) + 100000 ))
59
+
60
+
58
61
ani = animation .FuncAnimation (
59
62
fig , # Figure to update
60
63
functools .partial (update , line = line , text = text ,
0 commit comments