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