@@ -3906,10 +3906,33 @@ def format_ydata(self, y):
3906
3906
3907
3907
def format_coord (self , x , y ):
3908
3908
"""Return a format string formatting the *x*, *y* coordinates."""
3909
- return "x={} y={}" .format (
3910
- "???" if x is None else self .format_xdata (x ),
3911
- "???" if y is None else self .format_ydata (y ),
3912
- )
3909
+ x_twins = []
3910
+ y_twins = []
3911
+ twins = self ._twinned_axes .get_siblings (self )
3912
+ # Retrieve twins in the order of self.figure.axes to sort tied zorders (which is
3913
+ # the common case) by the order in which they are added to the figure.
3914
+ for ax in self .figure .axes :
3915
+ if ax in twins :
3916
+ if ax is self or ax ._sharex is self or self ._sharex is ax :
3917
+ x_twins .append (ax )
3918
+ if ax is self or ax ._sharey is self or self ._sharey is ax :
3919
+ y_twins .append (ax )
3920
+ if len (x_twins ) == len (y_twins ) == 1 :
3921
+ return "x={} y={}" .format (
3922
+ "???" if x is None else self .format_xdata (x ),
3923
+ "???" if y is None else self .format_ydata (y ))
3924
+ else :
3925
+ get_zorder = attrgetter ("zorder" )
3926
+ x_twins .sort (key = get_zorder )
3927
+ y_twins .sort (key = get_zorder )
3928
+ screen_xy = self .transData .transform ((x , y ))
3929
+ return "x={} y={}" .format (
3930
+ " / " .join (
3931
+ ax .format_xdata (ax .transData .inverted ().transform (screen_xy )[0 ])
3932
+ for ax in y_twins ),
3933
+ " / " .join (
3934
+ ax .format_xdata (ax .transData .inverted ().transform (screen_xy )[1 ])
3935
+ for ax in x_twins ))
3913
3936
3914
3937
def minorticks_on (self ):
3915
3938
"""
0 commit comments