Return the image value at the event position or *None* if the event is outside the image. See Also -------- matplotlib.artist.Artist.get_cursor_data
(self, event)
| 1001 | return (-0.5, numcols-0.5, -0.5, numrows-0.5) |
| 1002 | |
| 1003 | def get_cursor_data(self, event): |
| 1004 | """ |
| 1005 | Return the image value at the event position or *None* if the event is |
| 1006 | outside the image. |
| 1007 | |
| 1008 | See Also |
| 1009 | -------- |
| 1010 | matplotlib.artist.Artist.get_cursor_data |
| 1011 | """ |
| 1012 | xmin, xmax, ymin, ymax = self.get_extent() |
| 1013 | if self.origin == 'upper': |
| 1014 | ymin, ymax = ymax, ymin |
| 1015 | arr = self.get_array() |
| 1016 | data_extent = Bbox([[xmin, ymin], [xmax, ymax]]) |
| 1017 | array_extent = Bbox([[0, 0], [arr.shape[1], arr.shape[0]]]) |
| 1018 | trans = self.get_transform().inverted() |
| 1019 | trans += BboxTransform(boxin=data_extent, boxout=array_extent) |
| 1020 | point = trans.transform([event.x, event.y]) |
| 1021 | if any(np.isnan(point)): |
| 1022 | return None |
| 1023 | j, i = point.astype(int) |
| 1024 | # Clip the coordinates at array bounds |
| 1025 | if not (0 <= i < arr.shape[0]) or not (0 <= j < arr.shape[1]): |
| 1026 | return None |
| 1027 | else: |
| 1028 | return arr[i, j] |
| 1029 | |
| 1030 | |
| 1031 | class NonUniformImage(AxesImage): |
nothing calls this directly
no test coverage detected