Skip to content
forked from pydata/xarray

Commit

Permalink
facetgrid: fix case when vmin == vmax
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 29, 2020
1 parent 1416d5a commit b077270
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
3 changes: 2 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ Bug fixes
- Fix a regression where deleting a coordinate from a copied :py:class:`DataArray`
can affect the original :py:class:`Dataarray`. (:issue:`3899`, :pull:`3871`)
By `Todd Jennings <https://github.com/toddrjen>`_

- Fix ``FacetGrid`` when ``vmin == vmax``. (:issue:`3734`)
By `Deepak Cherian <https://github.com/dcherian>`_

Documentation
~~~~~~~~~~~~~
Expand Down
12 changes: 6 additions & 6 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,14 @@ def _determine_cmap_params(
norm.vmin = vmin
else:
if not vmin_was_none and vmin != norm.vmin:
raise ValueError(
"Cannot supply vmin and a norm" + " with a different vmin."
)
raise ValueError("Cannot supply vmin and a norm with a different vmin.")
vmin = norm.vmin

if norm.vmax is None:
norm.vmax = vmax
else:
if not vmax_was_none and vmax != norm.vmax:
raise ValueError(
"Cannot supply vmax and a norm" + " with a different vmax."
)
raise ValueError("Cannot supply vmax and a norm with a different vmax.")
vmax = norm.vmax

# if BoundaryNorm, then set levels
Expand All @@ -275,6 +271,10 @@ def _determine_cmap_params(
levels = ticker.tick_values(vmin, vmax)
vmin, vmax = levels[0], levels[-1]

# GH3734
if vmin == vmax:
vmin, _, vmax = mpl.ticker.LinearLocator(3).tick_values(vmin, vmax)

if extend is None:
extend = _determine_extend(calc_data, vmin, vmax)

Expand Down
15 changes: 11 additions & 4 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ def test_norm_sets_vmin_vmax(self):

for norm, extend in zip(
[
mpl.colors.LogNorm(),
mpl.colors.LogNorm(vmin + 1, vmax - 1),
mpl.colors.LogNorm(None, vmax - 1),
mpl.colors.LogNorm(vmin + 1, None),
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"],
):
Expand Down Expand Up @@ -1752,6 +1752,13 @@ def test_can_set_vmin_vmax(self):
clim = np.array(image.get_clim())
assert np.allclose(expected, clim)

@pytest.mark.slow
def test_vmin_vmax_equal(self):
# regression test for GH3734
fg = self.g.map_dataarray(xplt.imshow, "x", "y", vmin=50, vmax=50)
for mappable in fg._mappables:
assert mappable.norm.vmin != mappable.norm.vmax

@pytest.mark.slow
@pytest.mark.filterwarnings("ignore")
def test_can_set_norm(self):
Expand Down

0 comments on commit b077270

Please sign in to comment.