Skip to content

Commit f45d69f

Browse files
headtr1ckIllviljan
authored andcommitted
Fix static typing with Matplotlib 3.8 (pydata#8030)
* fix several typing issues with mpl3.8 * fix scatter plot typing and remove funky pyplot import * fix some more typing errors * fix some import errors * undo some typing errors * fix xylim typing * add forgotten import * ignore plotting overloads because None is Hashable * add whats-new entry * fix return type of hist * fix another xylim type * fix some more xylim types * change to T_DataArray * change accessor xylim to tuple * add missing return types * fix a typing error only on new mpl * add unused-ignore to error codes for old mpl * add more unused-ignore to error codes for old mpl * replace type: ignore[attr-defined] with assert hasattr * apply code review suggestions --------- Co-authored-by: Illviljan <[email protected]>
1 parent 3351f2f commit f45d69f

File tree

8 files changed

+306
-242
lines changed

8 files changed

+306
-242
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Breaking changes
4040
extracts and add the indexes from another :py:class:`Coordinates` object
4141
passed via ``coords`` (:pull:`8107`).
4242
By `Benoît Bovy <https://github.com/benbovy>`_.
43+
- Static typing of ``xlim`` and ``ylim`` arguments in plotting functions now must
44+
be ``tuple[float, float]`` to align with matplotlib requirements. (:issue:`7802`, :pull:`8030`).
45+
By `Michael Niklas <https://github.com/headtr1ck>`_.
4346

4447
Deprecations
4548
~~~~~~~~~~~~

xarray/core/options.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
from xarray.core.utils import FrozenDict
77

88
if TYPE_CHECKING:
9-
try:
10-
from matplotlib.colors import Colormap
11-
except ImportError:
12-
Colormap = str
9+
from matplotlib.colors import Colormap
10+
1311
Options = Literal[
1412
"arithmetic_join",
1513
"cmap_divergent",
@@ -164,11 +162,11 @@ class set_options:
164162
cmap_divergent : str or matplotlib.colors.Colormap, default: "RdBu_r"
165163
Colormap to use for divergent data plots. If string, must be
166164
matplotlib built-in colormap. Can also be a Colormap object
167-
(e.g. mpl.cm.magma)
165+
(e.g. mpl.colormaps["magma"])
168166
cmap_sequential : str or matplotlib.colors.Colormap, default: "viridis"
169167
Colormap to use for nondivergent data plots. If string, must be
170168
matplotlib built-in colormap. Can also be a Colormap object
171-
(e.g. mpl.cm.magma)
169+
(e.g. mpl.colormaps["magma"])
172170
display_expand_attrs : {"default", True, False}
173171
Whether to expand the attributes section for display of
174172
``DataArray`` or ``Dataset`` objects. Can be

0 commit comments

Comments
 (0)