|
13 | 13 |
|
14 | 14 | import matplotlib as mpl |
15 | 15 | from . import _api, cbook |
16 | | -from .colors import BoundaryNorm |
17 | | -from .cm import ScalarMappable |
18 | 16 | from .path import Path |
19 | 17 | from .transforms import (BboxBase, Bbox, IdentityTransform, Transform, TransformedBbox, |
20 | 18 | TransformedPatchPath, TransformedPath) |
@@ -1346,37 +1344,11 @@ def format_cursor_data(self, data): |
1346 | 1344 | -------- |
1347 | 1345 | get_cursor_data |
1348 | 1346 | """ |
1349 | | - if np.ndim(data) == 0 and isinstance(self, ScalarMappable): |
1350 | | - # This block logically belongs to ScalarMappable, but can't be |
1351 | | - # implemented in it because most ScalarMappable subclasses inherit |
1352 | | - # from Artist first and from ScalarMappable second, so |
1353 | | - # Artist.format_cursor_data would always have precedence over |
1354 | | - # ScalarMappable.format_cursor_data. |
1355 | | - n = self.cmap.N |
1356 | | - if np.ma.getmask(data): |
1357 | | - return "[]" |
1358 | | - normed = self.norm(data) |
1359 | | - if np.isfinite(normed): |
1360 | | - if isinstance(self.norm, BoundaryNorm): |
1361 | | - # not an invertible normalization mapping |
1362 | | - cur_idx = np.argmin(np.abs(self.norm.boundaries - data)) |
1363 | | - neigh_idx = max(0, cur_idx - 1) |
1364 | | - # use max diff to prevent delta == 0 |
1365 | | - delta = np.diff( |
1366 | | - self.norm.boundaries[neigh_idx:cur_idx + 2] |
1367 | | - ).max() |
1368 | | - elif self.norm.vmin == self.norm.vmax: |
1369 | | - # singular norms, use delta of 10% of only value |
1370 | | - delta = np.abs(self.norm.vmin * .1) |
1371 | | - else: |
1372 | | - # Midpoints of neighboring color intervals. |
1373 | | - neighbors = self.norm.inverse( |
1374 | | - (int(normed * n) + np.array([0, 1])) / n) |
1375 | | - delta = abs(neighbors - data).max() |
1376 | | - g_sig_digits = cbook._g_sig_digits(data, delta) |
1377 | | - else: |
1378 | | - g_sig_digits = 3 # Consistent with default below. |
1379 | | - return f"[{data:-#.{g_sig_digits}g}]" |
| 1347 | + if np.ndim(data) == 0 and hasattr(self, "_format_cursor_data_override"): |
| 1348 | + # workaround for ScalarMappable to be able to define its own |
| 1349 | + # format_cursor_data(). See ScalarMappable._format_cursor_data_override |
| 1350 | + # for details. |
| 1351 | + return self._format_cursor_data_override(data) |
1380 | 1352 | else: |
1381 | 1353 | try: |
1382 | 1354 | data[0] |
|
0 commit comments