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

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e62bc8

Browse files
committed
Tweak cursor coordinates display format.
1 parent 0f7821e commit 6e62bc8

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
@@ -3914,27 +3914,24 @@ def format_coord(self, x, y):
39143914
"""Return a format string formatting the *x*, *y* coordinates."""
39153915
twins = self._twinned_axes.get_siblings(self)
39163916
if len(twins) == 1:
3917-
return "x={} y={}".format(
3917+
return "(x, y) = ({}, {})".format(
39183918
"???" if x is None else self.format_xdata(x),
39193919
"???" if y is None else self.format_ydata(y))
3920-
x_twins = []
3921-
y_twins = []
3920+
screen_xy = self.transData.transform((x, y))
3921+
xy_strs = []
39223922
# Retrieve twins in the order of self.figure.axes to sort tied zorders (which is
39233923
# the common case) by the order in which they are added to the figure.
3924-
for ax in self.figure.axes:
3925-
if ax in twins:
3926-
if ax is self or ax._sharex is self or self._sharex is ax:
3927-
x_twins.append(ax)
3928-
if ax is self or ax._sharey is self or self._sharey is ax:
3929-
y_twins.append(ax)
3930-
screen_xy = self.transData.transform((x, y))
3931-
return "x={} y={}".format(
3932-
" | ".join(
3933-
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[0])
3934-
for ax in sorted(y_twins, key=attrgetter("zorder"))),
3935-
" | ".join(
3936-
ax.format_xdata(ax.transData.inverted().transform(screen_xy)[1])
3937-
for ax in sorted(x_twins, key=attrgetter("zorder"))))
3924+
for ax in sorted(
3925+
[ax for ax in self.figure.axes if (
3926+
ax in twins and (
3927+
ax is self
3928+
or ax._sharex is self or self._sharex is ax
3929+
or ax._sharey is self or self._sharey is ax))],
3930+
key=attrgetter("zorder")):
3931+
data_x, data_y = ax.transData.inverted().transform(screen_xy)
3932+
xy_strs.append(
3933+
"({}, {})".format(ax.format_xdata(data_x), ax.format_ydata(data_y)))
3934+
return "(x, y) = {}".format(" | ".join(xy_strs))
39383935

39393936
def minorticks_on(self):
39403937
"""

0 commit comments

Comments
 (0)
0