|
12 | 12 | Iterable,
|
13 | 13 | Literal,
|
14 | 14 | TypeVar,
|
| 15 | + cast, |
15 | 16 | )
|
16 | 17 |
|
17 | 18 | import numpy as np
|
|
41 | 42 | from matplotlib.quiver import QuiverKey
|
42 | 43 | from matplotlib.text import Annotation
|
43 | 44 |
|
| 45 | + from ..core.dataarray import DataArray |
| 46 | + |
| 47 | + |
44 | 48 | # Overrides axes.labelsize, xtick.major.size, ytick.major.size
|
45 | 49 | # from mpl.rcParams
|
46 | 50 | _FONTSIZE = "small"
|
@@ -402,18 +406,24 @@ def map_plot1d(
|
402 | 406 | hueplt_norm = _Normalize(hueplt)
|
403 | 407 | self._hue_var = hueplt
|
404 | 408 | cbar_kwargs = kwargs.pop("cbar_kwargs", {})
|
405 |
| - if not hueplt_norm.data_is_numeric: |
406 |
| - # TODO: Ticks seems a little too hardcoded, since it will always |
407 |
| - # show all the values. But maybe it's ok, since plotting hundreds |
408 |
| - # of categorical data isn't that meaningful anyway. |
409 |
| - cbar_kwargs.update(format=hueplt_norm.format, ticks=hueplt_norm.ticks) |
410 |
| - kwargs.update(levels=hueplt_norm.levels) |
411 |
| - if "label" not in cbar_kwargs: |
412 |
| - cbar_kwargs["label"] = label_from_attrs(hueplt_norm.data) |
413 |
| - cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs( |
414 |
| - func, hueplt_norm.values.to_numpy(), cbar_kwargs=cbar_kwargs, **kwargs |
415 |
| - ) |
416 |
| - self._cmap_extend = cmap_params.get("extend") |
| 409 | + |
| 410 | + if hueplt_norm.data is not None: |
| 411 | + if not hueplt_norm.data_is_numeric: |
| 412 | + # TODO: Ticks seems a little too hardcoded, since it will always |
| 413 | + # show all the values. But maybe it's ok, since plotting hundreds |
| 414 | + # of categorical data isn't that meaningful anyway. |
| 415 | + cbar_kwargs.update(format=hueplt_norm.format, ticks=hueplt_norm.ticks) |
| 416 | + kwargs.update(levels=hueplt_norm.levels) |
| 417 | + |
| 418 | + cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs( |
| 419 | + func, |
| 420 | + cast("DataArray", hueplt_norm.values).data, |
| 421 | + cbar_kwargs=cbar_kwargs, |
| 422 | + **kwargs, |
| 423 | + ) |
| 424 | + self._cmap_extend = cmap_params.get("extend") |
| 425 | + else: |
| 426 | + cmap_params = {} |
417 | 427 |
|
418 | 428 | # Handle sizes:
|
419 | 429 | _size_r = _MARKERSIZE_RANGE if func.__name__ == "scatter" else _LINEWIDTH_RANGE
|
@@ -513,6 +523,9 @@ def map_plot1d(
|
513 | 523 |
|
514 | 524 | if add_colorbar:
|
515 | 525 | # Colorbar is after legend so it correctly fits the plot:
|
| 526 | + if "label" not in cbar_kwargs: |
| 527 | + cbar_kwargs["label"] = label_from_attrs(hueplt_norm.data) |
| 528 | + |
516 | 529 | self.add_colorbar(**cbar_kwargs)
|
517 | 530 |
|
518 | 531 | return self
|
|
0 commit comments