Skip to content

Commit 2c8bb0d

Browse files
committed
Add NonUniformImage cursor format test
1 parent 1b56d96 commit 2c8bb0d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,33 @@ def test_cursor_data():
365365
assert im.get_cursor_data(event) == 44
366366

367367

368+
@pytest.mark.parametrize("xy, data", [
369+
[[0.5, 0.5], 0 + 0],
370+
[[0.5, 1.5], 0 + 1],
371+
[[4.5, 0.5], 16 + 0],
372+
[[9.5, 2.5], 81 + 4]
373+
]
374+
)
375+
def test_cursor_data_nonuniform(xy, data):
376+
from matplotlib.backend_bases import MouseEvent
377+
378+
# Non-linear set of x-values
379+
x = np.array([0, 1, 4, 9, 16])
380+
y = np.array([0, 1, 2, 3, 4])
381+
z = x[np.newaxis, :]**2 + y[:, np.newaxis]**2
382+
383+
fig, ax = plt.subplots()
384+
im = NonUniformImage(ax, extent=(x.min(), x.max(), y.min(), y.max()))
385+
im.set_data(x, y, z)
386+
ax.add_image(im)
387+
ax.set_xlim(x.min(), x.max())
388+
ax.set_ylim(y.min(), y.max())
389+
390+
xdisp, ydisp = ax.transData.transform(xy)
391+
event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp)
392+
assert im.get_cursor_data(event) == data, (im.get_cursor_data(event), data)
393+
394+
368395
@pytest.mark.parametrize(
369396
"data, text", [
370397
([[10001, 10000]], "[10001.000]"),

0 commit comments

Comments
 (0)