2
2
unicode_literals )
3
3
4
4
import six
5
-
5
+ from matplotlib . artist import Artist
6
6
import matplotlib .cbook as cbook
7
7
8
8
9
- class Container (tuple ):
9
+ class Container (tuple , Artist ):
10
10
"""
11
11
Base class for containers.
12
12
"""
@@ -17,92 +17,34 @@ def __repr__(self):
17
17
def __new__ (cls , * kl , ** kwargs ):
18
18
return tuple .__new__ (cls , kl [0 ])
19
19
20
- def __init__ (self , kl , label = None ):
21
-
22
- self .eventson = False # fire events only if eventson
23
- self ._oid = 0 # an observer id
24
- self ._propobservers = {} # a dict from oids to funcs
25
-
26
- self ._remove_method = None
27
-
28
- self .set_label (label )
29
-
30
- def set_remove_method (self , f ):
31
- self ._remove_method = f
20
+ def __init__ (self , kl , label = None , ** kwargs ):
21
+ Artist .__init__ (self , ** kwargs )
22
+ self .set_label (label = label )
32
23
33
24
def remove (self ):
25
+ # remove the children
34
26
for c in self :
35
27
c .remove ()
36
-
37
- if self ._remove_method :
38
- self ._remove_method (self )
39
-
40
- def __getstate__ (self ):
41
- d = self .__dict__ .copy ()
42
- # remove the unpicklable remove method, this will get re-added on load
43
- # (by the axes) if the artist lives on an axes.
44
- d ['_remove_method' ] = None
45
- return d
46
-
47
- def get_label (self ):
48
- """
49
- Get the label used for this artist in the legend.
50
- """
51
- return self ._label
52
-
53
- def set_label (self , s ):
54
- """
55
- Set the label to *s* for auto legend.
56
-
57
- ACCEPTS: string or anything printable with '%s' conversion.
58
- """
59
- if s is not None :
60
- self ._label = '%s' % (s , )
61
- else :
62
- self ._label = None
63
- self .pchanged ()
64
-
65
- def add_callback (self , func ):
66
- """
67
- Adds a callback function that will be called whenever one of
68
- the :class:`Artist`'s properties changes.
69
-
70
- Returns an *id* that is useful for removing the callback with
71
- :meth:`remove_callback` later.
72
- """
73
- oid = self ._oid
74
- self ._propobservers [oid ] = func
75
- self ._oid += 1
76
- return oid
77
-
78
- def remove_callback (self , oid ):
79
- """
80
- Remove a callback based on its *id*.
81
-
82
- .. seealso::
83
-
84
- :meth:`add_callback`
85
- For adding callbacks
86
-
87
- """
88
- try :
89
- del self ._propobservers [oid ]
90
- except KeyError :
91
- pass
92
-
93
- def pchanged (self ):
94
- """
95
- Fire an event when property changed, calling all of the
96
- registered callbacks.
97
- """
98
- for oid , func in list (six .iteritems (self ._propobservers )):
99
- func (self )
28
+ # call up to the Artist remove method
29
+ super (Container , self ).remove (self )
100
30
101
31
def get_children (self ):
102
32
return list (cbook .flatten (self ))
103
33
34
+ def draw (self , renderer , * args , ** kwargs ):
35
+ # just broadcast the draw down to children
36
+ for a in self :
37
+ a .draw (renderer , * args , ** kwargs )
38
+
104
39
105
40
class BarContainer (Container ):
41
+ def __new__ (cls , patches , errorbar = None , ** kwargs ):
42
+ if errorbar is None :
43
+ errorbar = tuple ()
44
+ else :
45
+ errorbar = tuple (errorbar )
46
+ patches = tuple (patches )
47
+ return super (BarContainer , cls ).__new__ (patches + errorbar , ** kwargs )
106
48
107
49
def __init__ (self , patches , errorbar = None , ** kwargs ):
108
50
self .patches = patches
0 commit comments