Skip to content

Commit 1b56d96

Browse files
Jaroza727dstansby
authored andcommitted
added format_cursor_data function to NonUniformImage class
1 parent 1247126 commit 1b56d96

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/matplotlib/image.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ def get_cursor_data(self, event):
10381038

10391039

10401040
class NonUniformImage(AxesImage):
1041-
mouseover = False # This class still needs its own get_cursor_data impl.
10421041

10431042
def __init__(self, ax, *, interpolation='nearest', **kwargs):
10441043
"""
@@ -1190,6 +1189,19 @@ def set_cmap(self, cmap):
11901189
raise RuntimeError('Cannot change colors after loading data')
11911190
super().set_cmap(cmap)
11921191

1192+
def get_cursor_data(self, event):
1193+
# docstring inherited
1194+
x, y = event.xdata, event.ydata
1195+
if (x < self._Ax[0] or x > self._Ax[-1] or
1196+
y < self._Ay[0] or y > self._Ay[-1]):
1197+
return None
1198+
j = np.searchsorted(self._Ax, x) - 1
1199+
i = np.searchsorted(self._Ay, y) - 1
1200+
try:
1201+
return self._A[i, j]
1202+
except IndexError:
1203+
return None
1204+
11931205

11941206
class PcolorImage(AxesImage):
11951207
"""

0 commit comments

Comments
 (0)