|
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,11 +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)" |
| 128 | + |
| 129 | + |
| 130 | +def test_location_event_position_twin(): |
| 131 | + fig, ax = plt.subplots() |
| 132 | + ax.set(xlim=(0, 10), ylim=(0, 20)) |
| 133 | + assert ax.format_coord(5., 5.) == "(x, y) = (5.00, 5.00)" |
| 134 | + ax.twinx().set(ylim=(0, 40)) |
| 135 | + assert ax.format_coord(5., 5.) == "(x, y) = (5.00, 5.00) | (5.00, 10.0)" |
| 136 | + ax.twiny().set(xlim=(0, 5)) |
| 137 | + assert (ax.format_coord(5., 5.) |
| 138 | + == "(x, y) = (5.00, 5.00) | (5.00, 10.0) | (2.50, 5.00)") |
131 | 139 |
|
132 | 140 |
|
133 | 141 | def test_pick(): |
|
0 commit comments