| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3971,27 +3971,24 @@ def format_coord(self, x, y): | |||
| 3971 | 3971 | """Return a format string formatting the *x*, *y* coordinates.""" | |
| 3972 | 3972 | twins = self._twinned_axes.get_siblings(self) | |
| 3973 | 3973 | if len(twins) == 1: | |
| 3974 | - return "x={} y={}".format( | ||
| 3974 | + return "(x, y) = ({}, {})".format( | ||
| 3975 | 3975 | "???" if x is None else self.format_xdata(x), | |
| 3976 | 3976 | "???" if y is None else self.format_ydata(y)) | |
| 3977 | - x_twins = [] | ||
| 3978 | - y_twins = [] | ||
| 3977 | + screen_xy = self.transData.transform((x, y)) | ||
| 3978 | + xy_strs = [] | ||
| 3979 | 3979 | # Retrieve twins in the order of self.figure.axes to sort tied zorders (which is | |
| 3980 | 3980 | # the common case) by the order in which they are added to the figure. | |
| 3981 | - for ax in self.figure.axes: | ||
| 3982 | - if ax in twins: | ||
| 3983 | - if ax is self or ax._sharex is self or self._sharex is ax: | ||
| 3984 | - x_twins.append(ax) | ||
| 3985 | - if ax is self or ax._sharey is self or self._sharey is ax: | ||
| 3986 | - y_twins.append(ax) | ||
| 3987 | - screen_xy = self.transData.transform((x, y)) | ||
| 3988 | - return "x={} y={}".format( | ||
| 3989 | - " | ".join( | ||
| 3990 | - ax.format_xdata(ax.transData.inverted().transform(screen_xy)[0]) | ||
| 3991 | - for ax in sorted(y_twins, key=attrgetter("zorder"))), | ||
| 3992 | - " | ".join( | ||
| 3993 | - ax.format_xdata(ax.transData.inverted().transform(screen_xy)[1]) | ||
| 3994 | - for ax in sorted(x_twins, key=attrgetter("zorder")))) | ||
| 3981 | + for ax in sorted( | ||
| 3982 | + [ax for ax in self.figure.axes if ( | ||
| 3983 | + ax in twins and ( | ||
| 3984 | + ax is self | ||
| 3985 | + or ax._sharex is self or self._sharex is ax | ||
| 3986 | + or ax._sharey is self or self._sharey is ax))], | ||
| 3987 | + key=attrgetter("zorder")): | ||
| 3988 | + data_x, data_y = ax.transData.inverted().transform(screen_xy) | ||
| 3989 | + xy_strs.append( | ||
| 3990 | + "({}, {})".format(ax.format_xdata(data_x), ax.format_ydata(data_y))) | ||
| 3991 | + return "(x, y) = {}".format(" | ".join(xy_strs)) | ||
| 3995 | 3992 | ||
| 3996 | 3993 | def minorticks_on(self): | |
| 3997 | 3994 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,3 @@ | |||
| 1 | - import re | ||
| 2 | - | ||
| 3 | 1 | from matplotlib import path, transforms | |
| 4 | 2 | from matplotlib.backend_bases import ( | |
| 5 | 3 | FigureCanvasBase, KeyEvent, LocationEvent, MouseButton, MouseEvent, | |
@@ -123,21 +121,21 @@ def test_location_event_position(x, y): | |||
| 123 | 121 | assert event.y == int(y) | |
| 124 | 122 | assert isinstance(event.y, int) | |
| 125 | 123 | if x is not None and y is not None: | |
| 126 | - assert re.match( | ||
| 127 | - f"x={ax.format_xdata(x)} +y={ax.format_ydata(y)}", | ||
| 128 | - ax.format_coord(x, y)) | ||
| 124 | + assert (ax.format_coord(x, y) | ||
| 125 | + == f"(x, y) = ({ax.format_xdata(x)}, {ax.format_ydata(y)})") | ||
| 129 | 126 | ax.fmt_xdata = ax.fmt_ydata = lambda x: "foo" | |
| 130 | - assert re.match("x=foo +y=foo", ax.format_coord(x, y)) | ||
| 127 | + assert ax.format_coord(x, y) == "(x, y) = (foo, foo)" | ||
| 131 | 128 | ||
| 132 | 129 | ||
| 133 | 130 | def test_location_event_position_twin(): | |
| 134 | 131 | fig, ax = plt.subplots() | |
| 135 | 132 | ax.set(xlim=(0, 10), ylim=(0, 20)) | |
| 136 | - assert ax.format_coord(5., 5.) == "x=5.00 y=5.00" | ||
| 133 | + assert ax.format_coord(5., 5.) == "(x, y) = (5.00, 5.00)" | ||
| 137 | 134 | ax.twinx().set(ylim=(0, 40)) | |
| 138 | - assert ax.format_coord(5., 5.) == "x=5.00 y=5.00 | 10.00" | ||
| 135 | + assert ax.format_coord(5., 5.) == "(x, y) = (5.00, 5.00) | (5.00, 10.0)" | ||
| 139 | 136 | ax.twiny().set(xlim=(0, 5)) | |
| 140 | - assert ax.format_coord(5., 5.) == "x=5.00 | 2.50 y=5.00 | 10.00" | ||
| 137 | + assert (ax.format_coord(5., 5.) | ||
| 138 | + == "(x, y) = (5.00, 5.00) | (5.00, 10.0) | (2.50, 5.00)") | ||
| 141 | 139 | ||
| 142 | 140 | ||
| 143 | 141 | def test_pick(): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments