Skip to content

facetgrid: fix case when vmin == vmax #3916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(2).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