Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boundarynorm fix #7553

Merged
merged 19 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a288a2
Update utils.py
veenstrajelmer Feb 23, 2023
3d84b2c
Update test_plot.py
veenstrajelmer Feb 23, 2023
c9e4a41
Merge pull request #1 from veenstrajelmer/patch-1
veenstrajelmer Feb 23, 2023
4effc03
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2023
c2ce3c1
fix as suggested by jklymak
veenstrajelmer Mar 10, 2023
9bbc690
Merge branch 'main' into patch-2
veenstrajelmer Mar 10, 2023
1c764c2
updated testcase
veenstrajelmer Mar 10, 2023
3a60f1d
enabled type checking of test_discrete_colormap_provided_boundary_nor…
veenstrajelmer Mar 16, 2023
317cab8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2023
5b5335d
updated whats-new.rst
veenstrajelmer Mar 16, 2023
35ed8d1
Merge branch 'patch-2' of https://github.com/veenstrajelmer/xarray in…
veenstrajelmer Mar 16, 2023
b6d6cb1
enabled type checking of test_discrete_colormap_provided_boundary_nor…
veenstrajelmer Mar 16, 2023
a1c0391
Merge branch 'main' into patch-2
veenstrajelmer Mar 16, 2023
45eaf42
Merge branch 'patch-2' of https://github.com/veenstrajelmer/xarray in…
veenstrajelmer Mar 16, 2023
e7306a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 16, 2023
4dfb3ac
Update doc/whats-new.rst
veenstrajelmer Mar 27, 2023
0936a66
Merge branch 'main' into patch-2
veenstrajelmer Mar 27, 2023
b3a7c4a
moved whatsnew for pull 7553 to 2023.04 section
veenstrajelmer Mar 27, 2023
bdaf380
Merge branch 'main' into patch-2
veenstrajelmer Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Deprecations
Bug fixes
~~~~~~~~~

- Proper plotting with BoundaryNorm type argument in :py:meth:`DataArray.plot(norm=matplotlib.colors.BoundaryNorm)`. (:issue:`4061`, :issue:`7014`,:pull:`7553`)
veenstrajelmer marked this conversation as resolved.
Show resolved Hide resolved
By `Jelmer Veenstra <https://github.com/veenstrajelmer>`_.
- Improve error message when using in :py:meth:`Dataset.drop_vars` to state which variables can't be dropped. (:pull:`7518`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
- Require to explicitly defining optional dimensions such as hue
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _determine_cmap_params(
if extend is None:
extend = _determine_extend(calc_data, vmin, vmax)

if levels is not None or isinstance(norm, mpl.colors.BoundaryNorm):
if (levels is not None) and (not isinstance(norm, mpl.colors.BoundaryNorm)):
veenstrajelmer marked this conversation as resolved.
Show resolved Hide resolved
cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled)
norm = newnorm if norm is None else norm

Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,13 @@ def test_discrete_colormap_provided_boundary_norm(self) -> None:
primitive = self.darray.plot.contourf(norm=norm)
np.testing.assert_allclose(primitive.levels, norm.boundaries)

def test_discrete_colormap_provided_boundary_norm_matching_cmap_levels(
self,
) -> None:
norm = mpl.colors.BoundaryNorm([0, 5, 10, 15], 4)
primitive = self.darray.plot.contourf(norm=norm)
assert primitive.colorbar.norm.Ncmap == primitive.colorbar.norm.N

veenstrajelmer marked this conversation as resolved.
Show resolved Hide resolved

class Common2dMixin:
"""
Expand Down