Skip to content

Commit bd84186

Browse files
authored
Fix contour when levels is scalar and norm is provided. (#3914)
Fixes #3735
1 parent 3e5dd6e commit bd84186

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

doc/whats-new.rst

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Bug fixes
9191
By `Deepak Cherian <https://github.com/dcherian>`_
9292
- Fix :py:class:`~xarray.plot.FacetGrid` when ``vmin == vmax``. (:issue:`3734`)
9393
By `Deepak Cherian <https://github.com/dcherian>`_
94+
- Fix plotting when ``levels`` is a scalar and ``norm`` is provided. (:issue:`3735`)
95+
By `Deepak Cherian <https://github.com/dcherian>`_
9496
- Fix bug where plotting line plots with 2D coordinates depended on dimension
9597
order. (:issue:`3933`)
9698
By `Tom Nicholas <https://github.com/TomNicholas>`_.

xarray/plot/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _determine_cmap_params(
268268
cmap = OPTIONS["cmap_sequential"]
269269

270270
# Handle discrete levels
271-
if levels is not None and norm is None:
271+
if levels is not None:
272272
if is_scalar(levels):
273273
if user_minmax:
274274
levels = np.linspace(vmin, vmax, levels)

xarray/tests/test_plot.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -854,21 +854,22 @@ def test_norm_sets_vmin_vmax(self):
854854
vmin = self.data.min()
855855
vmax = self.data.max()
856856

857-
for norm, extend in zip(
857+
for norm, extend, levels in zip(
858858
[
859+
mpl.colors.Normalize(),
859860
mpl.colors.Normalize(),
860861
mpl.colors.Normalize(vmin + 0.1, vmax - 0.1),
861862
mpl.colors.Normalize(None, vmax - 0.1),
862863
mpl.colors.Normalize(vmin + 0.1, None),
863864
],
864-
["neither", "both", "max", "min"],
865+
["neither", "neither", "both", "max", "min"],
866+
[7, None, None, None, None],
865867
):
866868

867869
test_min = vmin if norm.vmin is None else norm.vmin
868870
test_max = vmax if norm.vmax is None else norm.vmax
869871

870-
cmap_params = _determine_cmap_params(self.data, norm=norm)
871-
872+
cmap_params = _determine_cmap_params(self.data, norm=norm, levels=levels)
872873
assert cmap_params["vmin"] == test_min
873874
assert cmap_params["vmax"] == test_max
874875
assert cmap_params["extend"] == extend

0 commit comments

Comments
 (0)