Skip to content

Commit

Permalink
Fix contour when levels is scalar and norm is provided. (#3914)
Browse files Browse the repository at this point in the history
Fixes #3735
  • Loading branch information
dcherian authored May 12, 2020
1 parent 3e5dd6e commit bd84186
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Bug fixes
By `Deepak Cherian <https://github.com/dcherian>`_
- Fix :py:class:`~xarray.plot.FacetGrid` when ``vmin == vmax``. (:issue:`3734`)
By `Deepak Cherian <https://github.com/dcherian>`_
- Fix plotting when ``levels`` is a scalar and ``norm`` is provided. (:issue:`3735`)
By `Deepak Cherian <https://github.com/dcherian>`_
- Fix bug where plotting line plots with 2D coordinates depended on dimension
order. (:issue:`3933`)
By `Tom Nicholas <https://github.com/TomNicholas>`_.
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _determine_cmap_params(
cmap = OPTIONS["cmap_sequential"]

# Handle discrete levels
if levels is not None and norm is None:
if levels is not None:
if is_scalar(levels):
if user_minmax:
levels = np.linspace(vmin, vmax, levels)
Expand Down
9 changes: 5 additions & 4 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,21 +854,22 @@ def test_norm_sets_vmin_vmax(self):
vmin = self.data.min()
vmax = self.data.max()

for norm, extend in zip(
for norm, extend, levels in zip(
[
mpl.colors.Normalize(),
mpl.colors.Normalize(),
mpl.colors.Normalize(vmin + 0.1, vmax - 0.1),
mpl.colors.Normalize(None, vmax - 0.1),
mpl.colors.Normalize(vmin + 0.1, None),
],
["neither", "both", "max", "min"],
["neither", "neither", "both", "max", "min"],
[7, None, None, None, None],
):

test_min = vmin if norm.vmin is None else norm.vmin
test_max = vmax if norm.vmax is None else norm.vmax

cmap_params = _determine_cmap_params(self.data, norm=norm)

cmap_params = _determine_cmap_params(self.data, norm=norm, levels=levels)
assert cmap_params["vmin"] == test_min
assert cmap_params["vmax"] == test_max
assert cmap_params["extend"] == extend
Expand Down

0 comments on commit bd84186

Please sign in to comment.