10
10
11
11
class ParasiteAxesBase :
12
12
13
- def get_images_artists (self ):
14
- artists = {a for a in self .get_children () if a .get_visible ()}
15
- images = {a for a in self .images if a .get_visible ()}
16
- return list (images ), list (artists - images )
17
-
18
- def __init__ (self , parent_axes , ** kwargs ):
13
+ def __init__ (self , parent_axes ,
14
+ aux_transform = None , viewlim_mode = None ,
15
+ ** kwargs ):
19
16
self ._parent_axes = parent_axes
17
+ self .transAux = aux_transform
18
+ self .set_viewlim_mode (viewlim_mode )
20
19
kwargs ["frameon" ] = False
21
20
super ().__init__ (parent_axes .figure , parent_axes ._position , ** kwargs )
22
21
@@ -25,6 +24,11 @@ def cla(self):
25
24
martist .setp (self .get_children (), visible = False )
26
25
self ._get_lines = self ._parent_axes ._get_lines
27
26
27
+ def get_images_artists (self ):
28
+ artists = {a for a in self .get_children () if a .get_visible ()}
29
+ images = {a for a in self .images if a .get_visible ()}
30
+ return list (images ), list (artists - images )
31
+
28
32
def pick (self , mouseevent ):
29
33
# This most likely goes to Artist.pick (depending on axes_class given
30
34
# to the factory), which only handles pick events registered on the
@@ -37,6 +41,49 @@ def pick(self, mouseevent):
37
41
and self in mouseevent .inaxes .parasites ):
38
42
a .pick (mouseevent )
39
43
44
+ # aux_transform support
45
+
46
+ def _set_lim_and_transforms (self ):
47
+ if self .transAux is not None :
48
+ self .transAxes = self ._parent_axes .transAxes
49
+ self .transData = self .transAux + self ._parent_axes .transData
50
+ self ._xaxis_transform = mtransforms .blended_transform_factory (
51
+ self .transData , self .transAxes )
52
+ self ._yaxis_transform = mtransforms .blended_transform_factory (
53
+ self .transAxes , self .transData )
54
+ else :
55
+ super ()._set_lim_and_transforms ()
56
+
57
+ def set_viewlim_mode (self , mode ):
58
+ _api .check_in_list ([None , "equal" , "transform" ], mode = mode )
59
+ self ._viewlim_mode = mode
60
+
61
+ def get_viewlim_mode (self ):
62
+ return self ._viewlim_mode
63
+
64
+ @cbook .deprecated ("3.4" , alternative = "apply_aspect" )
65
+ def update_viewlim (self ):
66
+ return self ._update_viewlim
67
+
68
+ def _update_viewlim (self ): # Inline after deprecation elapses.
69
+ viewlim = self ._parent_axes .viewLim .frozen ()
70
+ mode = self .get_viewlim_mode ()
71
+ if mode is None :
72
+ pass
73
+ elif mode == "equal" :
74
+ self .axes .viewLim .set (viewlim )
75
+ elif mode == "transform" :
76
+ self .axes .viewLim .set (
77
+ viewlim .transformed (self .transAux .inverted ()))
78
+ else :
79
+ _api .check_in_list ([None , "equal" , "transform" ], mode = mode )
80
+
81
+ def apply_aspect (self , position = None ):
82
+ self ._update_viewlim ()
83
+ super ().apply_aspect ()
84
+
85
+ # end of aux_transform support
86
+
40
87
41
88
@functools .lru_cache (None )
42
89
def parasite_axes_class_factory (axes_class = None ):
@@ -55,11 +102,10 @@ def parasite_axes_class_factory(axes_class=None):
55
102
ParasiteAxes = parasite_axes_class_factory (Axes )
56
103
57
104
105
+ @cbook .deprecated ("3.4" , alternative = "ParasiteAxesBase" )
58
106
class ParasiteAxesAuxTransBase :
59
107
def __init__ (self , parent_axes , aux_transform , viewlim_mode = None ,
60
108
** kwargs ):
61
- self .transAux = aux_transform
62
- self .set_viewlim_mode (viewlim_mode )
63
109
super ().__init__ (parent_axes , ** kwargs )
64
110
65
111
def _set_lim_and_transforms (self ):
@@ -99,6 +145,7 @@ def apply_aspect(self, position=None):
99
145
super ().apply_aspect ()
100
146
101
147
148
+ @cbook .deprecated ("3.4" , alternative = "parasite_axes_class_factory" )
102
149
@functools .lru_cache (None )
103
150
def parasite_axes_auxtrans_class_factory (axes_class = None ):
104
151
if axes_class is None :
@@ -117,16 +164,29 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
117
164
{'name' : 'parasite_axes' })
118
165
119
166
120
- ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory (ParasiteAxes )
167
+ # Also deprecated.
168
+ with cbook ._suppress_matplotlib_deprecation_warning ():
169
+ ParasiteAxesAuxTrans = parasite_axes_auxtrans_class_factory (ParasiteAxes )
121
170
122
171
123
172
class HostAxesBase :
124
173
def __init__ (self , * args , ** kwargs ):
125
174
self .parasites = []
126
175
super ().__init__ (* args , ** kwargs )
127
176
128
- def get_aux_axes (self , tr , viewlim_mode = "equal" , axes_class = ParasiteAxes ):
129
- parasite_axes_class = parasite_axes_auxtrans_class_factory (axes_class )
177
+ def get_aux_axes (self , tr = None , viewlim_mode = "equal" , axes_class = Axes ):
178
+ """
179
+ Add a parasite axes to this host.
180
+
181
+ Despite this method's name, this should actually be thought of as an
182
+ ``add_parasite_axes`` method.
183
+
184
+ *tr* may be `.Transform`, in which case the following relation will
185
+ hold: ``parasite.transData = tr + host.transData``. Alternatively, it
186
+ may be None (the default), no special relationship will hold between
187
+ the parasite's and the host's ``transData``.
188
+ """
189
+ parasite_axes_class = parasite_axes_class_factory (axes_class )
130
190
ax2 = parasite_axes_class (self , tr , viewlim_mode )
131
191
# note that ax2.transData == tr + ax1.transData
132
192
# Anything you draw in ax2 will match the ticks and grids of ax1.
@@ -236,13 +296,11 @@ def twin(self, aux_trans=None, axes_class=None):
236
296
if axes_class is None :
237
297
axes_class = self ._get_base_axes ()
238
298
239
- parasite_axes_auxtrans_class = \
240
- parasite_axes_auxtrans_class_factory (axes_class )
299
+ parasite_axes_class = parasite_axes_class_factory (axes_class )
241
300
242
301
if aux_trans is None :
243
302
aux_trans = mtransforms .IdentityTransform ()
244
- ax2 = parasite_axes_auxtrans_class (
245
- self , aux_trans , viewlim_mode = "transform" )
303
+ ax2 = parasite_axes_class (self , aux_trans , viewlim_mode = "transform" )
246
304
self .parasites .append (ax2 )
247
305
ax2 ._remove_method = self ._remove_any_twin
248
306
0 commit comments