| 1 | diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py |
| 2 | --- a/lib/matplotlib/artist.py |
| 3 | +++ b/lib/matplotlib/artist.py |
| 4 | @@ -12,6 +12,7 @@ |
| 5 | |
| 6 | import matplotlib as mpl |
| 7 | from . import _api, cbook |
| 8 | +from .colors import BoundaryNorm |
| 9 | from .cm import ScalarMappable |
| 10 | from .path import Path |
| 11 | from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox, |
| 12 | @@ -1303,10 +1304,20 @@ def format_cursor_data(self, data): |
| 13 | return "[]" |
| 14 | normed = self.norm(data) |
| 15 | if np.isfinite(normed): |
| 16 | - # Midpoints of neighboring color intervals. |
| 17 | - neighbors = self.norm.inverse( |
| 18 | - (int(self.norm(data) * n) + np.array([0, 1])) / n) |
| 19 | - delta = abs(neighbors - data).max() |
| 20 | + if isinstance(self.norm, BoundaryNorm): |
| 21 | + # not an invertible normalization mapping |
| 22 | + cur_idx = np.argmin(np.abs(self.norm.boundaries - data)) |
| 23 | + neigh_idx = max(0, cur_idx - 1) |
| 24 | + # use max diff to prevent delta == 0 |
| 25 | + delta = np.diff( |
| 26 | + self.norm.boundaries[neigh_idx:cur_idx + 2] |
| 27 | + ).max() |
| 28 | + |
| 29 | + else: |
| 30 | + # Midpoints of neighboring color intervals. |
| 31 | + neighbors = self.norm.inverse( |
| 32 | + (int(normed * n) + np.array([0, 1])) / n) |
| 33 | + delta = abs(neighbors - data).max() |
| 34 | g_sig_digits = cbook._g_sig_digits(data, delta) |
| 35 | else: |
| 36 | g_sig_digits = 3 # Consistent with default below. |