@@ -4666,7 +4666,7 @@ def _update_twinned_axes_patch_visibility(self):
46664666 if patch is not None :
46674667 patch .set_visible ((ax is bottom ) and ax .get_frame_on ())
46684668
4669- def _make_twin_axes (self , * args , zorder = None , ** kwargs ):
4669+ def _make_twin_axes (self , * args , delta_zorder = None , ** kwargs ):
46704670 """Make a twinx Axes of self. This is used for twinx and twiny."""
46714671 if 'sharex' in kwargs and 'sharey' in kwargs :
46724672 # The following line is added in v2.2 to avoid breaking Seaborn,
@@ -4683,13 +4683,15 @@ def _make_twin_axes(self, *args, zorder=None, **kwargs):
46834683 [0 , 0 , 1 , 1 ], self .transAxes ))
46844684 self .set_adjustable ('datalim' )
46854685 twin .set_adjustable ('datalim' )
4686- twin .set_zorder (self .zorder if zorder is None else zorder )
4686+ original_zorder = self .get_zorder ()
4687+ twin .set_zorder (original_zorder if delta_zorder is None
4688+ else original_zorder + delta_zorder )
46874689
46884690 self ._twinned_axes .join (self , twin )
46894691 self ._update_twinned_axes_patch_visibility ()
46904692 return twin
46914693
4692- def twinx (self , axes_class = None , * , zorder = None , ** kwargs ):
4694+ def twinx (self , axes_class = None , * , delta_zorder = None , ** kwargs ):
46934695 """
46944696 Create a twin Axes sharing the xaxis.
46954697
@@ -4710,9 +4712,11 @@ def twinx(self, axes_class=None, *, zorder=None, **kwargs):
47104712
47114713 .. versionadded:: 3.11
47124714
4713- zorder : float, optional
4714- The zorder of the twin Axes. By default, the twin has the same
4715- zorder as the original Axes.
4715+ delta_zorder : float, optional
4716+ A zorder offset for the twin Axes, relative to the original Axes.
4717+ The twin's zorder is set to ``self.get_zorder() + delta_zorder``.
4718+ By default (*delta_zorder* is None), the twin has the same zorder
4719+ as the original Axes.
47164720
47174721 kwargs : dict
47184722 The keyword arguments passed to `.Figure.add_subplot` or `.Figure.add_axes`.
@@ -4731,7 +4735,8 @@ def twinx(self, axes_class=None, *, zorder=None, **kwargs):
47314735 """
47324736 if axes_class :
47334737 kwargs ["axes_class" ] = axes_class
4734- ax2 = self ._make_twin_axes (sharex = self , zorder = zorder , ** kwargs )
4738+ ax2 = self ._make_twin_axes (sharex = self , delta_zorder = delta_zorder ,
4739+ ** kwargs )
47354740 ax2 .yaxis .tick_right ()
47364741 ax2 .yaxis .set_label_position ('right' )
47374742 ax2 .yaxis .set_offset_position ('right' )
@@ -4741,7 +4746,7 @@ def twinx(self, axes_class=None, *, zorder=None, **kwargs):
47414746 ax2 .xaxis .units = self .xaxis .units
47424747 return ax2
47434748
4744- def twiny (self , axes_class = None , * , zorder = None , ** kwargs ):
4749+ def twiny (self , axes_class = None , * , delta_zorder = None , ** kwargs ):
47454750 """
47464751 Create a twin Axes sharing the yaxis.
47474752
@@ -4762,9 +4767,11 @@ def twiny(self, axes_class=None, *, zorder=None, **kwargs):
47624767
47634768 .. versionadded:: 3.11
47644769
4765- zorder : float, optional
4766- The zorder of the twin Axes. By default, the twin has the same
4767- zorder as the original Axes.
4770+ delta_zorder : float, optional
4771+ A zorder offset for the twin Axes, relative to the original Axes.
4772+ The twin's zorder is set to ``self.get_zorder() + delta_zorder``.
4773+ By default (*delta_zorder* is None), the twin has the same zorder
4774+ as the original Axes.
47684775
47694776 kwargs : dict
47704777 The keyword arguments passed to `.Figure.add_subplot` or `.Figure.add_axes`.
@@ -4783,7 +4790,8 @@ def twiny(self, axes_class=None, *, zorder=None, **kwargs):
47834790 """
47844791 if axes_class :
47854792 kwargs ["axes_class" ] = axes_class
4786- ax2 = self ._make_twin_axes (sharey = self , zorder = zorder , ** kwargs )
4793+ ax2 = self ._make_twin_axes (sharey = self , delta_zorder = delta_zorder ,
4794+ ** kwargs )
47874795 ax2 .xaxis .tick_top ()
47884796 ax2 .xaxis .set_label_position ('top' )
47894797 ax2 .set_autoscaley_on (self .get_autoscaley_on ())
0 commit comments