| 1 | [Bug]: scalar mappable format_cursor_data crashes on BoundarNorm |
| 2 | ### Bug summary |
| 3 | |
| 4 | In 3.5.0 if you do: |
| 5 | |
| 6 | ```python |
| 7 | import matplotlib.pyplot as plt |
| 8 | import numpy as np |
| 9 | import matplotlib as mpl |
| 10 | |
| 11 | fig, ax = plt.subplots() |
| 12 | norm = mpl.colors.BoundaryNorm(np.linspace(-4, 4, 5), 256) |
| 13 | X = np.random.randn(10, 10) |
| 14 | pc = ax.imshow(X, cmap='RdBu_r', norm=norm) |
| 15 | ``` |
| 16 | |
| 17 | and mouse over the image, it crashes with |
| 18 | |
| 19 | ``` |
| 20 | File "/Users/jklymak/matplotlib/lib/matplotlib/artist.py", line 1282, in format_cursor_data |
| 21 | neighbors = self.norm.inverse( |
| 22 | File "/Users/jklymak/matplotlib/lib/matplotlib/colors.py", line 1829, in inverse |
| 23 | raise ValueError("BoundaryNorm is not invertible") |
| 24 | ValueError: BoundaryNorm is not invertible |
| 25 | ``` |
| 26 | |
| 27 | and interaction stops. |
| 28 | |
| 29 | Not sure if we should have a special check here, a try-except, or actually just make BoundaryNorm approximately invertible. |
| 30 | |
| 31 | |
| 32 | ### Matplotlib Version |
| 33 | |
| 34 | main 3.5.0 |
| 35 | |
| 36 | |
| 37 | [Bug]: scalar mappable format_cursor_data crashes on BoundarNorm |
| 38 | ### Bug summary |
| 39 | |
| 40 | In 3.5.0 if you do: |
| 41 | |
| 42 | ```python |
| 43 | import matplotlib.pyplot as plt |
| 44 | import numpy as np |
| 45 | import matplotlib as mpl |
| 46 | |
| 47 | fig, ax = plt.subplots() |
| 48 | norm = mpl.colors.BoundaryNorm(np.linspace(-4, 4, 5), 256) |
| 49 | X = np.random.randn(10, 10) |
| 50 | pc = ax.imshow(X, cmap='RdBu_r', norm=norm) |
| 51 | ``` |
| 52 | |
| 53 | and mouse over the image, it crashes with |
| 54 | |
| 55 | ``` |
| 56 | File "/Users/jklymak/matplotlib/lib/matplotlib/artist.py", line 1282, in format_cursor_data |
| 57 | neighbors = self.norm.inverse( |
| 58 | File "/Users/jklymak/matplotlib/lib/matplotlib/colors.py", line 1829, in inverse |
| 59 | raise ValueError("BoundaryNorm is not invertible") |
| 60 | ValueError: BoundaryNorm is not invertible |
| 61 | ``` |
| 62 | |
| 63 | and interaction stops. |
| 64 | |
| 65 | Not sure if we should have a special check here, a try-except, or actually just make BoundaryNorm approximately invertible. |
| 66 | |
| 67 | |
| 68 | ### Matplotlib Version |
| 69 | |
| 70 | main 3.5.0 |
| 71 | |
| 72 | |