1010
1111class ParasiteAxesBase :
1212
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 ):
1915 self ._parent_axes = parent_axes
16+ self .transAux = aux_transform
17+ self .set_viewlim_mode (viewlim_mode )
2018 kwargs ["frameon" ] = False
2119 super ().__init__ (parent_axes .figure , parent_axes ._position , ** kwargs )
2220
@@ -25,6 +23,11 @@ def cla(self):
2523 martist .setp (self .get_children (), visible = False )
2624 self ._get_lines = self ._parent_axes ._get_lines
2725
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+
2831 def pick (self , mouseevent ):
2932 # This most likely goes to Artist.pick (depending on axes_class given
3033 # to the factory), which only handles pick events registered on the
@@ -37,6 +40,49 @@ def pick(self, mouseevent):
3740 and self in mouseevent .inaxes .parasites ):
3841 a .pick (mouseevent )
3942
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+
4086
4187@functools .lru_cache (None )
4288def parasite_axes_class_factory (axes_class = None ):
@@ -55,12 +101,13 @@ def parasite_axes_class_factory(axes_class=None):
55101ParasiteAxes = parasite_axes_class_factory (Axes )
56102
57103
104+ @cbook .deprecated ("3.4" , alternative = "ParasiteAxesBase" )
58105class ParasiteAxesAuxTransBase :
59106 def __init__ (self , parent_axes , aux_transform , viewlim_mode = None ,
60107 ** 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 )
64111
65112 def _set_lim_and_transforms (self ):
66113 self .transAxes = self ._parent_axes .transAxes
@@ -99,6 +146,7 @@ def apply_aspect(self, position=None):
99146 super ().apply_aspect ()
100147
101148
149+ @cbook .deprecated ("3.4" , alternative = "parasite_axes_class_factory" )
102150@functools .lru_cache (None )
103151def parasite_axes_auxtrans_class_factory (axes_class = None ):
104152 if axes_class is None :
@@ -117,17 +165,30 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
117165 {'name' : 'parasite_axes' })
118166
119167
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 )
121171
122172
123173class HostAxesBase :
124174 def __init__ (self , * args , ** kwargs ):
125175 self .parasites = []
126176 super ().__init__ (* args , ** kwargs )
127177
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 )
131192 # note that ax2.transData == tr + ax1.transData
132193 # Anything you draw in ax2 will match the ticks and grids of ax1.
133194 self .parasites .append (ax2 )
@@ -236,13 +297,11 @@ def twin(self, aux_trans=None, axes_class=None):
236297 if axes_class is None :
237298 axes_class = self ._get_base_axes ()
238299
239- parasite_axes_auxtrans_class = \
240- parasite_axes_auxtrans_class_factory (axes_class )
300+ parasite_axes_class = parasite_axes_class_factory (axes_class )
241301
242302 if aux_trans is None :
243303 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" )
246305 self .parasites .append (ax2 )
247306 ax2 ._remove_method = self ._remove_any_twin
248307
0 commit comments