8000 Add a test for image cursor data · matplotlib/matplotlib@7626394 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7626394

Browse files
committed
Add a test for image cursor data
1 parent 07745c8 commit 7626394

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/matplotlib/tests/test_image.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,39 @@ def test_imsave_color_alpha():
158158

159159
assert_array_equal(data, arr_buf)
160160

161+
162+
@cleanup
163+
def test_cursor_data():
164+
from matplotlib.backend_bases import MouseEvent
165+
166+
fig, ax = plt.subplots()
167+
im = ax.imshow(np.arange(100).reshape(10, 10), origin='upper')
168+
169+
x, y = 4, 4
170+
xdisp, ydisp = ax.transData.transform_point([x, y])
171+
172+
event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp)
173+
assert im.get_zdata(event) == 44
174+
175+
ax.clear()
176+
im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower')
177+
178+
x, y = 4, 4
179+
xdisp, ydisp = ax.transData.transform_point([x, y])
180+
181+
event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp)
182+
assert im.get_zdata(event) == 44
183+
184+
fig, ax = plt.subplots()
185+
im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5])
186+
187+
x, y = 0.25, 0.25
188+
xdisp, ydisp = ax.transData.transform_point([x, y])
189+
190+
event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp)
191+
assert im.get_zdata(event) == 55
192+
193+
161194
@image_comparison(baseline_images=['image_clip'])
162195
def test_image_clip():
163196
from math import pi

0 commit comments

Comments
 (0)
0