diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 40c30fa33db9..28a007118280 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1008,7 +1008,6 @@ def format_cursor_data(self, data): class NonUniformImage(AxesImage): - mouseover = False # This class still needs its own get_cursor_data impl. def __init__(self, ax, *, interpolation='nearest', **kwargs): """ @@ -1132,6 +1131,19 @@ def set_cmap(self, cmap): raise RuntimeError('Cannot change colors after loading data') super().set_cmap(cmap) + def get_cursor_data(self, event): + # docstring inherited + x, y = event.xdata, event.ydata + if (x < self._Ax[0] or x > self._Ax[-1] or + y < self._Ay[0] or y > self._Ay[-1]): + return None + j = np.searchsorted(self._Ax, x) - 1 + i = np.searchsorted(self._Ay, y) - 1 + try: + return self._A[i, j] + except IndexError: + return None + class PcolorImage(AxesImage): """