From 4ca47e48332ff554cf957e80f09620336c00be5c Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 21 Jun 2019 18:12:58 -0400 Subject: [PATCH 1/3] Test for levels + provided cmap --- xarray/tests/test_plot.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index a0952cac47e..2d9668dac6e 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -775,13 +775,14 @@ def test_discrete_colormap_list_of_levels(self): @pytest.mark.slow def test_discrete_colormap_int_levels(self): - for extend, levels, vmin, vmax in [('neither', 7, None, None), - ('neither', 7, None, 20), - ('both', 7, 4, 8), - ('min', 10, 4, 15)]: + for extend, levels, vmin, vmax, cmap in [ + ('neither', 7, None, None, None), + ('neither', 7, None, 20, mpl.cm.RdBu), + ('both', 7, 4, 8, None), + ('min', 10, 4, 15, None)]: for kind in ['imshow', 'pcolormesh', 'contourf', 'contour']: primitive = getattr(self.darray.plot, kind)( - levels=levels, vmin=vmin, vmax=vmax) + levels=levels, vmin=vmin, vmax=vmax, cmap=cmap) assert levels >= \ len(primitive.norm.boundaries) - 1 if vmax is None: From eb058d29afdc153b0c04a3a0709961bb6f4188d5 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 21 Jun 2019 18:13:53 -0400 Subject: [PATCH 2/3] Revert "plot: If provided with colormap do not modify it. (#2935)" This reverts commit ab3972294860447f9515c7b7b0a04838db061496. --- doc/whats-new.rst | 2 -- xarray/plot/utils.py | 3 +-- xarray/tests/test_plot.py | 21 ++------------------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index ca50856a25e..52fa102f7fa 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -75,8 +75,6 @@ Bug fixes By `Mayeul d'Avezac `_. - Return correct count for scalar datetime64 arrays (:issue:`2770`) By `Dan Nowacki `_. -- Fix facetgrid colormap bug when ``extend=True``. (:issue:`2932`) - By `Deepak Cherian `_. - Increased support for `missing_value` (:issue:`2871`) diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index 18215479d8c..c9f72b177c6 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -264,8 +264,7 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None, if extend is None: extend = _determine_extend(calc_data, vmin, vmax) - if ((levels is not None or isinstance(norm, mpl.colors.BoundaryNorm)) - and (not isinstance(cmap, mpl.colors.Colormap))): + if levels is not None or isinstance(norm, mpl.colors.BoundaryNorm): cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled) norm = newnorm if norm is None else norm diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 2d9668dac6e..600f10c9f5c 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -4,10 +4,12 @@ import numpy as np import pandas as pd import pytest +from numpy.testing import assert_array_equal import xarray as xr import xarray.plot as xplt from xarray import DataArray +from xarray.coding.times import _import_cftime from xarray.plot.plot import _infer_interval_breaks from xarray.plot.utils import ( _build_discrete_cmap, _color_palette, _determine_cmap_params, @@ -537,25 +539,6 @@ def test_cmap_sequential_option(self): cmap_params = _determine_cmap_params(self.data) assert cmap_params['cmap'] == 'magma' - def test_do_nothing_if_provided_cmap(self): - cmap_list = [ - mpl.colors.LinearSegmentedColormap.from_list('name', ['r', 'g']), - mpl.colors.ListedColormap(['r', 'g', 'b']) - ] - - # can't parametrize with mpl objects when mpl is absent - for cmap in cmap_list: - cmap_params = _determine_cmap_params(self.data, - cmap=cmap, - levels=7) - assert cmap_params['cmap'] is cmap - - def test_do_something_if_provided_str_cmap(self): - cmap = 'RdBu_r' - cmap_params = _determine_cmap_params(self.data, cmap=cmap, levels=7) - assert cmap_params['cmap'] is not cmap - assert isinstance(cmap_params['cmap'], mpl.colors.ListedColormap) - def test_cmap_sequential_explicit_option(self): with xr.set_options(cmap_sequential=mpl.cm.magma): cmap_params = _determine_cmap_params(self.data) From 76b0c26f673bcd4e49ea8ac3355a9611ff9b5343 Mon Sep 17 00:00:00 2001 From: dcherian Date: Sat, 22 Jun 2019 11:51:00 -0400 Subject: [PATCH 3/3] lint --- xarray/tests/test_plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 600f10c9f5c..0dc5fb320f0 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -4,7 +4,6 @@ import numpy as np import pandas as pd import pytest -from numpy.testing import assert_array_equal import xarray as xr import xarray.plot as xplt