Skip to content

Commit e79eaf5

Browse files
veenstrajelmerpre-commit-ci[bot]dcherian
authored
boundarynorm fix (#7553)
* Update utils.py Proposing update to fix #7014 * Update test_plot.py added testcase for #7014 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix as suggested by jklymak * updated testcase * enabled type checking of test_discrete_colormap_provided_boundary_norm_matching_cmap_levels() * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * updated whats-new.rst * enabled type checking of test_discrete_colormap_provided_boundary_norm_matching_cmap_levels(), again * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update doc/whats-new.rst Co-authored-by: Deepak Cherian <[email protected]> * moved whatsnew for pull 7553 to 2023.04 section --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Deepak Cherian <[email protected]>
1 parent 020b4c0 commit e79eaf5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Bug fixes
3939
By `Shreyal Gupta <https://github.com/Ravenin7>`_ and `Michael Niklas <https://github.com/headtr1ck>`_.
4040
- Improve error message when trying to open a file which you do not have permission to read (:issue:`6523`, :pull:`7629`).
4141
By `Thomas Coleman <https://github.com/ColemanTom>`_.
42+
- Proper plotting when passing :py:class:`~matplotlib.colors.BoundaryNorm` type argument in :py:meth:`DataArray.plot`. (:issue:`4061`, :issue:`7014`,:pull:`7553`)
43+
By `Jelmer Veenstra <https://github.com/veenstrajelmer>`_.
4244

4345
Documentation
4446
~~~~~~~~~~~~~

xarray/plot/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def _determine_cmap_params(
304304
if extend is None:
305305
extend = _determine_extend(calc_data, vmin, vmax)
306306

307-
if levels is not None or isinstance(norm, mpl.colors.BoundaryNorm):
307+
if (levels is not None) and (not isinstance(norm, mpl.colors.BoundaryNorm)):
308308
cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled)
309309
norm = newnorm if norm is None else norm
310310

xarray/tests/test_plot.py

+7
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,13 @@ def test_discrete_colormap_provided_boundary_norm(self) -> None:
12041204
primitive = self.darray.plot.contourf(norm=norm)
12051205
np.testing.assert_allclose(primitive.levels, norm.boundaries)
12061206

1207+
def test_discrete_colormap_provided_boundary_norm_matching_cmap_levels(
1208+
self,
1209+
) -> None:
1210+
norm = mpl.colors.BoundaryNorm([0, 5, 10, 15], 4)
1211+
primitive = self.darray.plot.contourf(norm=norm)
1212+
assert primitive.colorbar.norm.Ncmap == primitive.colorbar.norm.N
1213+
12071214

12081215
class Common2dMixin:
12091216
"""

0 commit comments

Comments
 (0)