forked from t-makaro/animatplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
77 lines (63 loc) · 2.17 KB
/
update.py
File metadata and controls
77 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from .base import Block
from warnings import warn
class Update(Block):
"""For providing a custom update method
This block allows you to write a custom update method to provide
functionality not available with other blocks.
Parameters
----------
func : callable
This function will be called once for each frame of the animation.
The first argument to this function must be an integer
representing the frame number. It should return a matplotlib
artist.
length : int
the number of frames to display
fargs : list, optional
a list of arguments to pass into func
ax : a matplotlib.axes.Axes, optional
The matplotlib axes to attach the block to.
Defaults to matplotlib.pyplot.gca()
Attributes
----------
ax : matplotlib.axes.Axes
The matplotlib axes that the block is attached to.
"""
def __init__(self, func, length, fargs=[], ax=None):
self.func = func
self.length = length
self.fargs = fargs
super().__init__(ax)
func(0, *fargs)
def _update(self, i):
self.func(i, *self.fargs)
def __len__(self):
return self.length
class Nuke(Update):
"""For when the other blocks just won't do
This block will clear the axes and redraw using a provided
function on every frame.
This block can be used with other blocks so long as other
blocks are attached to a different axes.
Only use this block as a last resort. Using the block
is like nuking an ant hill. Hence the name.
Parameters
----------
func : callable
The first argument to this function must be an integer
representing the frame number.
length : int
the number of frames to display
fargs : list, optional
a list of arguments to pass into func
ax : a matplotlib.axes.Axes, optional
The matplotlib axes to attach the block to.
Defaults to matplotlib.pyplot.gca()
Attributes
----------
ax : matplotlib.axes.Axes
The matplotlib axes that the block is attached to.
"""
def _update(self, i):
self.ax.clear()
self.func(i, *self.fargs)