1+ from matplotlib .artist import Artist
12import matplotlib .cbook as cbook
2- import matplotlib .artist as martist
33
44
55class Container (tuple ):
@@ -18,84 +18,30 @@ def __new__(cls, *args, **kwargs):
1818 return tuple .__new__ (cls , args [0 ])
1919
2020 def __init__ (self , kl , label = None ):
21-
2221 self .eventson = False # fire events only if eventson
2322 self ._oid = 0 # an observer id
2423 self ._propobservers = {} # a dict from oids to funcs
25-
2624 self ._remove_method = None
27-
2825 self .set_label (label )
2926
3027 def remove (self ):
3128 for c in cbook .flatten (
32- self , scalarp = lambda x : isinstance (x , martist . Artist )):
29+ self , scalarp = lambda x : isinstance (x , Artist )):
3330 if c is not None :
3431 c .remove ()
3532
3633 if self ._remove_method :
3734 self ._remove_method (self )
3835
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-
9636 def get_children (self ):
9737 return [child for child in cbook .flatten (self ) if child is not None ]
9838
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+
9945
10046class BarContainer (Container ):
10147 """
0 commit comments