8000 Tweak cursor coordinates display format. · matplotlib/matplotlib@b62e6d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit b62e6d7

Browse files
anntzerksunden
authored andcommitted
Tweak cursor coordinates display format.
1 parent ca7da36 commit b62e6d7

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,27 +3977,24 @@ def format_coord(self, x, y):
39773977
"""Return a format string formatting the *x*, *y* coordinates."""
39783978
twins = self._twinned_axes.get_siblings(self)
39793979
if len(twins) == 1:
3980-
return "x={} y={}".format(
3980+
return "(x, y) = ({}, {})".format(
39813981
"???" if x is None else self.format_xdata(x),
39823982
"???" if y is None else self.format_ydata(y))
3983-
x_twins = []
3984-
y_twins = []
3983+
screen_xy = self.transData.transform((x, y))
3984+
xy_strs = []
39853985
# Retrieve twins in the order of self.figure.axes to sort tied zorders (which is
39863986
# the common case) by the order in which they are added to the figure.
3987-
for ax in self.figure.axes:
3988-
if ax in twins:
3989-
if ax is self or ax._sharex is self or self._sharex is ax:
3990-
x_twins.append(ax)
3991-
if ax is self or ax._sharey is self or self._sharey is ax:
3992-
y_twins.append(ax)
3993-
screen_xy = self.transData.transform((x, y))
3994-
return "x={} y={}".format(
3995-
" | ".join(
3996-
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[0])
3997-
for ax in sorted(y_twins, key=attrgetter("zorder"))),
3998-
" | ".join(
3999-
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[1])
4000-
for ax in sorted(x_twins, key=attrgetter("zorder"))))
3987+
for ax in sorted(
3988+
[ax for ax in self.figure.axes if (
3989+
ax in twins and (
3990+
ax is self
3991+
or ax._sharex is self or self._sharex is ax
3992+
or ax._sharey is self or self._sharey is ax))],
3993+
key=attrgetter("zorder")):
3994+
data_x, data_y = ax.transData.inverted().transform(screen_xy)
3995+
xy_strs.append(
3996+
"({}, {})".format(ax.format_xdata(data_x), ax.format_ydata(data_y)))
3997+
return "(x, y) = {}".format(" | ".join(xy_strs))
40013998

40023999
def minorticks_on(self):
40034000
"""

0 commit comments

Comments
 (0)
0