10
10
import numpy as np
11
11
12
12
13
- class ParasiteAxesBase ( object ) :
13
+ class ParasiteAxesBase :
14
14
15
15
def get_images_artists (self ):
16
16
artists = {a for a in self .get_children () if a .get_visible ()}
@@ -21,11 +21,10 @@ def get_images_artists(self):
21
21
def __init__ (self , parent_axes , ** kwargs ):
22
22
self ._parent_axes = parent_axes
23
23
kwargs ["frameon" ] = False
24
- self ._get_base_axes_attr ("__init__" )(
25
- self , parent_axes .figure , parent_axes ._position , ** kwargs )
24
+ super ().__init__ (parent_axes .figure , parent_axes ._position , ** kwargs )
26
25
27
26
def cla (self ):
28
- self . _get_base_axes_attr ( "cla" )( self )
27
+ super (). cla ( )
29
28
30
29
martist .setp (self .get_children (), visible = False )
31
30
self ._get_lines = self ._parent_axes ._get_lines
@@ -45,18 +44,14 @@ def parasite_axes_class_factory(axes_class=None):
45
44
if axes_class is None :
46
45
axes_class = Axes
47
46
48
- def _get_base_axes_attr (self , attrname ):
49
- return getattr (axes_class , attrname )
50
-
51
47
return type ("%sParasite" % axes_class .__name__ ,
52
- (ParasiteAxesBase , axes_class ),
53
- {'_get_base_axes_attr' : _get_base_axes_attr })
48
+ (ParasiteAxesBase , axes_class ), {})
54
49
55
50
56
51
ParasiteAxes = parasite_axes_class_factory ()
57
52
58
53
59
- class ParasiteAxesAuxTransBase ( object ) :
54
+ class ParasiteAxesAuxTransBase :
60
55
def __init__ (self , parent_axes , aux_transform , viewlim_mode = None ,
61
56
** kwargs ):
62
57
@@ -87,7 +82,6 @@ def set_viewlim_mode(self, mode):
87
82
def get_viewlim_mode (self ):
88
83
return self ._viewlim_mode
89
84
90
-
91
85
def update_viewlim (self ):
92
86
viewlim = self ._parent_axes .viewLim .frozen ()
93
87
mode = self .get_viewlim_mode ()
@@ -100,8 +94,7 @@ def update_viewlim(self):
100
94
else :
101
95
raise ValueError ("Unknown mode : %s" % (self ._viewlim_mode ,))
102
96
103
-
104
- def _pcolor (self , method_name , * XYC , ** kwargs ):
97
+ def _pcolor (self , super_pcolor , * XYC , ** kwargs ):
105
98
if len (XYC ) == 1 :
106
99
C = XYC [0 ]
107
100
ny , nx = C .shape
@@ -113,29 +106,26 @@ def _pcolor(self, method_name, *XYC, **kwargs):
113
106
else :
114
107
X , Y , C = XYC
115
108
116
- pcolor_routine = self ._get_base_axes_attr (method_name )
117
-
118
109
if "transform" in kwargs :
119
- mesh = pcolor_routine (self , X , Y , C , ** kwargs )
110
+ mesh = super_pcolor (self , X , Y , C , ** kwargs )
120
111
else :
121
112
orig_shape = X .shape
122
113
xy = np .vstack ([X .flat , Y .flat ])
123
114
xyt = xy .transpose ()
124
115
wxy = self .transAux .transform (xyt )
125
116
gx , gy = wxy [:,0 ].reshape (orig_shape ), wxy [:,1 ].reshape (orig_shape )
126
- mesh = pcolor_routine (self , gx , gy , C , ** kwargs )
117
+ mesh = super_pcolor (self , gx , gy , C , ** kwargs )
127
118
mesh .set_transform (self ._parent_axes .transData )
128
119
129
120
return mesh
130
121
131
122
def pcolormesh (self , * XYC , ** kwargs ):
132
- return self ._pcolor (" pcolormesh" , * XYC , ** kwargs )
123
+ return self ._pcolor (super (). pcolormesh , * XYC , ** kwargs )
133
124
134
125
def pcolor (self , * XYC , ** kwargs ):
135
- return self ._pcolor ("pcolor" , * XYC , ** kwargs )
136
-
126
+ return self ._pcolor (super ().pcolor , * XYC , ** kwargs )
137
127
138
- def _contour (self , method_name , * XYCL , ** kwargs ):
128
+ def _contour (self , super_contour , * XYCL , ** kwargs ):
139
129
140
130
if len (XYCL ) <= 2 :
141
131
C = XYCL [0 ]
@@ -150,32 +140,29 @@ def _contour(self, method_name, *XYCL, **kwargs):
150
140
X , Y = XYCL [:2 ]
151
141
CL = XYCL [2 :]
152
142
153
- contour_routine = self ._get_base_axes_attr (method_name )
154
-
155
143
if "transform" in kwargs :
156
- cont = contour_routine (self , X , Y , * CL , ** kwargs )
144
+ cont = super_contour (self , X , Y , * CL , ** kwargs )
157
145
else :
158
146
orig_shape = X .shape
159
147
xy = np .vstack ([X .flat , Y .flat ])
160
148
xyt = xy .transpose ()
161
149
wxy = self .transAux .transform (xyt )
162
150
gx , gy = wxy [:,0 ].reshape (orig_shape ), wxy [:,1 ].reshape (orig_shape )
163
- cont = contour_routine (self , gx , gy , * CL , ** kwargs )
151
+ cont = super_contour (self , gx , gy , * CL , ** kwargs )
164
152
for c in cont .collections :
165
153
c .set_transform (self ._parent_axes .transData )
166
154
167
155
return cont
168
156
169
157
def contour (self , * XYCL , ** kwargs ):
170
- return self ._contour (" contour" , * XYCL , ** kwargs )
158
+ return self ._contour (super (). contour , * XYCL , ** kwargs )
171
159
172
160
def contourf (self , * XYCL , ** kwargs ):
173
- return self ._contour (" contourf" , * XYCL , ** kwargs )
161
+ return self ._contour (super (). contourf , * XYCL , ** kwargs )
174
162
175
163
def apply_aspect (self , position = None ):
176
164
self .update_viewlim ()
177
- self ._get_base_axes_attr ("apply_aspect" )(self )
178
- #ParasiteAxes.apply_aspect()
165
+ super ().apply_aspect ()
179
166
180
167
181
168
@functools .lru_cache (None )
@@ -209,10 +196,10 @@ def _get_handles(ax):
209
196
return handles
210
197
211
198
212
- class HostAxesBase ( object ) :
199
+ class HostAxesBase :
213
200
def __init__ (self , * args , ** kwargs ):
214
201
self .parasites = []
215
- self . _get_base_axes_attr ( "__init__" )( self , * args , ** kwargs )
202
+ super (). __init__ ( * args , ** kwargs )
216
203
217
204
def get_aux_axes (self , tr , viewlim_mode = "equal" , axes_class = None ):
218
205
parasite_axes_class = parasite_axes_auxtrans_class_factory (axes_class )
@@ -224,13 +211,9 @@ def get_aux_axes(self, tr, viewlim_mode="equal", axes_class=None):
224
211
return ax2
225
212
226
213
def _get_legend_handles (self , legend_handler_map = None ):
227
- # don't use this!
228
- Axes_get_legend_handles = self ._get_base_axes_attr ("_get_legend_handles" )
229
- all_handles = list (Axes_get_legend_handles (self , legend_handler_map ))
230
-
214
+ all_handles = super ()._get_legend_handles ()
231
215
for ax in self .parasites :
232
216
all_handles .extend (ax ._get_legend_handles (legend_handler_map ))
233
-
234
217
return all_handles
235
218
236
219
def draw (self , renderer ):
@@ -257,14 +240,14 @@ def draw(self, renderer):
257
240
self .images .extend (images )
258
241
self .artists .extend (artists )
259
242
260
- self . _get_base_axes_attr ( "draw" )( self , renderer )
243
+ super (). draw ( renderer )
261
244
self .artists = orig_artists
262
245
self .images = orig_images
263
246
264
247
def cla (self ):
265
248
for ax in self .parasites :
266
249
ax .cla ()
267
- self . _get_base_axes_attr ( "cla" )( self )
250
+ super (). cla ( )
268
251
269
252
def twinx (self , axes_class = None ):
270
253
"""
@@ -361,15 +344,10 @@ def _remove_method(h):
361
344
return ax2
362
345
363
346
def get_tightbbox (self , renderer , call_axes_locator = True ):
364
-
365
347
bbs = [ax .get_tightbbox (renderer , call_axes_locator )
366
348
for ax in self .parasites ]
367
- get_tightbbox = self ._get_base_axes_attr ("get_tightbbox" )
368
- bbs .append (get_tightbbox (self , renderer , call_axes_locator ))
369
-
370
- _bbox = Bbox .union ([b for b in bbs if b .width != 0 or b .height != 0 ])
371
-
372
- return _bbox
349
+ bbs .append (super ().get_tightbbox (renderer , call_axes_locator ))
350
+ return Bbox .union ([b for b in bbs if b .width != 0 or b .height != 0 ])
373
351
374
352
375
353
@functools .lru_cache (None )
@@ -380,13 +358,9 @@ def host_axes_class_factory(axes_class=None):
380
358
def _get_base_axes (self ):
381
359
return axes_class
382
360
383
- def _get_base_axes_attr (self , attrname ):
384
- return getattr (axes_class , attrname )
385
-
386
361
return type ("%sHostAxes" % axes_class .__name__ ,
387
362
(HostAxesBase , axes_class ),
388
- {'_get_base_axes_attr' : _get_base_axes_attr ,
389
- '_get_base_axes' : _get_base_axes })
363
+ {'_get_base_axes' : _get_base_axes })
390
364
391
365
392
366
def host_subplot_class_factory (axes_class ):
0 commit comments