Skip to content

Commit 19cb99d

Browse files
authored
facetgrid: fix case when vmin == vmax (#3916)
* facetgrid: fix case when vmin == vmax Fixes #3734 * minor fix.
1 parent 8a1c933 commit 19cb99d

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Bug fixes
5656
- Fix a regression where deleting a coordinate from a copied :py:class:`DataArray`
5757
can affect the original :py:class:`Dataarray`. (:issue:`3899`, :pull:`3871`)
5858
By `Todd Jennings <https://github.com/toddrjen>`_
59-
59+
- Fix ``FacetGrid`` when ``vmin == vmax``. (:issue:`3734`)
60+
By `Deepak Cherian <https://github.com/dcherian>`_
6061

6162
Documentation
6263
~~~~~~~~~~~~~

xarray/plot/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,14 @@ def _determine_cmap_params(
237237
norm.vmin = vmin
238238
else:
239239
if not vmin_was_none and vmin != norm.vmin:
240-
raise ValueError(
241-
"Cannot supply vmin and a norm" + " with a different vmin."
242-
)
240+
raise ValueError("Cannot supply vmin and a norm with a different vmin.")
243241
vmin = norm.vmin
244242

245243
if norm.vmax is None:
246244
norm.vmax = vmax
247245
else:
248246
if not vmax_was_none and vmax != norm.vmax:
249-
raise ValueError(
250-
"Cannot supply vmax and a norm" + " with a different vmax."
251-
)
247+
raise ValueError("Cannot supply vmax and a norm with a different vmax.")
252248
vmax = norm.vmax
253249

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

274+
# GH3734
275+
if vmin == vmax:
276+
vmin, vmax = mpl.ticker.LinearLocator(2).tick_values(vmin, vmax)
277+
278278
if extend is None:
279279
extend = _determine_extend(calc_data, vmin, vmax)
280280

xarray/tests/test_plot.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,10 @@ def test_norm_sets_vmin_vmax(self):
833833

834834
for norm, extend in zip(
835835
[
836-
mpl.colors.LogNorm(),
837-
mpl.colors.LogNorm(vmin + 1, vmax - 1),
838-
mpl.colors.LogNorm(None, vmax - 1),
839-
mpl.colors.LogNorm(vmin + 1, None),
836+
mpl.colors.Normalize(),
837+
mpl.colors.Normalize(vmin + 0.1, vmax - 0.1),
838+
mpl.colors.Normalize(None, vmax - 0.1),
839+
mpl.colors.Normalize(vmin + 0.1, None),
840840
],
841841
["neither", "both", "max", "min"],
842842
):
@@ -1752,6 +1752,13 @@ def test_can_set_vmin_vmax(self):
17521752
clim = np.array(image.get_clim())
17531753
assert np.allclose(expected, clim)
17541754

1755+
@pytest.mark.slow
1756+
def test_vmin_vmax_equal(self):
1757+
# regression test for GH3734
1758+
fg = self.g.map_dataarray(xplt.imshow, "x", "y", vmin=50, vmax=50)
1759+
for mappable in fg._mappables:
1760+
assert mappable.norm.vmin != mappable.norm.vmax
1761+
17551762
@pytest.mark.slow
17561763
@pytest.mark.filterwarnings("ignore")
17571764
def test_can_set_norm(self):

0 commit comments

Comments
 (0)