()
| 201 | |
| 202 | |
| 203 | def test_cursor_data(): |
| 204 | from matplotlib.backend_bases import MouseEvent |
| 205 | |
| 206 | fig, ax = plt.subplots() |
| 207 | im = ax.imshow(np.arange(100).reshape(10, 10), origin='upper') |
| 208 | |
| 209 | x, y = 4, 4 |
| 210 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 211 | |
| 212 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 213 | assert im.get_cursor_data(event) == 44 |
| 214 | |
| 215 | # Now try for a point outside the image |
| 216 | # Tests issue #4957 |
| 217 | x, y = 10.1, 4 |
| 218 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 219 | |
| 220 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 221 | assert im.get_cursor_data(event) is None |
| 222 | |
| 223 | # Hmm, something is wrong here... I get 0, not None... |
| 224 | # But, this works further down in the tests with extents flipped |
| 225 | #x, y = 0.1, -0.1 |
| 226 | #xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 227 | #event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 228 | #z = im.get_cursor_data(event) |
| 229 | #assert z is None, "Did not get None, got %d" % z |
| 230 | |
| 231 | ax.clear() |
| 232 | # Now try with the extents flipped. |
| 233 | im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower') |
| 234 | |
| 235 | x, y = 4, 4 |
| 236 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 237 | |
| 238 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 239 | assert im.get_cursor_data(event) == 44 |
| 240 | |
| 241 | fig, ax = plt.subplots() |
| 242 | im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5]) |
| 243 | |
| 244 | x, y = 0.25, 0.25 |
| 245 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 246 | |
| 247 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 248 | assert im.get_cursor_data(event) == 55 |
| 249 | |
| 250 | # Now try for a point outside the image |
| 251 | # Tests issue #4957 |
| 252 | x, y = 0.75, 0.25 |
| 253 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 254 | |
| 255 | event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) |
| 256 | assert im.get_cursor_data(event) is None |
| 257 | |
| 258 | x, y = 0.01, -0.01 |
| 259 | xdisp, ydisp = ax.transData.transform_point([x, y]) |
| 260 |
nothing calls this directly
no test coverage detected