1
+ from matplotlib .artist import Artist
1
2
import matplotlib .cbook as cbook
2
- import matplotlib .artist as martist
3
3
4
4
5
5
class Container (tuple ):
@@ -18,84 +18,30 @@ def __new__(cls, *args, **kwargs):
18
18
return tuple .__new__ (cls , args [0 ])
19
19
20
20
def __init__ (self , kl , label = None ):
21
-
22
21
self .eventson = False # fire events only if eventson
23
22
self ._oid = 0 # an observer id
24
23
self ._propobservers = {} # a dict from oids to funcs
25
-
26
24
self ._remove_method = None
27
-
28
25
self .set_label (label )
29
26
30
27
def remove (self ):
31
28
for c in cbook .flatten (
32
- self , scalarp = lambda x : isinstance (x , martist . Artist )):
29
+ self , scalarp = lambda x : isinstance (x , Artist )):
33
30
if c is not None :
34
31
c .remove ()
35
32
36
33
if self ._remove_method :
37
34
self ._remove_method (self )
38
35
39
- def get_label (self ):
40
- """
41
- Get the label used for this artist in the legend.
42
- """
43
- return self ._label
44
-
45
- def set_label (self , s ):
46
- """
47
- Set the label to *s* for auto legend.
48
-
49
- Parameters
50
- ----------
51
- s : object
52
- Any object other than None gets converted to its `str`.
53
- """
54
- if s is not None :
55
- self ._label = str (s )
56
- else :
57
- self ._label = None
58
- self .pchanged ()
59
-
60
- def add_callback (self , func ):
61
- """
62
- Adds a callback function that will be called whenever one of
63
- the :class:`Artist`'s properties changes.
64
-
65
- Returns an *id* that is useful for removing the callback with
66
- :meth:`remove_callback` later.
67
- """
68
- oid = self ._oid
69
- self ._propobservers [oid ] = func
70
- self ._oid += 1
71
- return oid
72
-
73
- def remove_callback (self , oid ):
74
- """
75
- Remove a callback based on its *id*.
76
-
77
- .. seealso::
78
-
79
- :meth:`add_callback`
80
- For adding callbacks
81
-
82
- """
83
- try :
84
- del self ._propobservers [oid ]
85
- except KeyError :
86
- pass
87
-
88
- def pchanged (self ):
89
- """
90
- Fire an event when property changed, calling all of the
91
- registered callbacks.
92
- """
93
- for oid , func in list (self ._propobservers .items ()):
94
- func (self )
95
-
96
36
def get_children (self ):
97
37
return [child for child in cbook .flatten (self ) if child is not None ]
98
38
39
+ get_label = Artist .get_label
40
+ set_label = Artist .set_label
41
+ add_callback = Artist .add_callback
42
+ remove_callback = Artist .remove_callback
43
+ pchanged = Artist .pchanged
44
+
99
45
100
46
class BarContainer (Container ):
101
47
"""
0 commit comments