From f02b90b401808bfb4f0f555fb7fa1cc21ed8334d Mon Sep 17 00:00:00 2001 From: dcherian Date: Tue, 20 Feb 2018 08:59:57 -0800 Subject: [PATCH] facetgrid: unset cmap if colors is specified. --- doc/whats-new.rst | 2 ++ xarray/plot/facetgrid.py | 11 +++++++++++ xarray/tests/test_plot.py | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 8b200103303..e2baa05fbc7 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -43,6 +43,8 @@ Bug fixes - Fix the precision drop after indexing datetime64 arrays (:issue:`1932`). By `Keisuke Fujii `_. +- Fix kwarg `colors` clashing with auto-inferred `cmap` (:issue:`1461`) + By `Deepak Cherian `_. .. _whats-new.0.10.1: diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index badd44b25db..fd94439db4f 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -221,6 +221,14 @@ def map_dataarray(self, func, x, y, **kwargs): self : FacetGrid object """ + + cmapkw = kwargs.get('cmap') + colorskw = kwargs.get('colors') + + # colors is mutually exclusive with cmap + if cmapkw and colorskw: + raise ValueError("Can't specify both cmap and colors.") + # These should be consistent with xarray.plot._plot2d cmap_kwargs = {'plot_data': self.data.values, # MPL default @@ -233,6 +241,9 @@ def map_dataarray(self, func, x, y, **kwargs): cmap_params = _determine_cmap_params(**cmap_kwargs) + if colorskw is not None: + cmap_params['cmap'] = None + # Order is important func_kwargs = kwargs.copy() func_kwargs.update(cmap_params) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 46410cd53e3..672a9e4a579 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -902,6 +902,10 @@ def test_facetgrid_cmap(self): # check that all colormaps are the same assert len(set(m.get_cmap().name for m in fg._mappables)) == 1 + def test_cmap_and_color_both(self): + with pytest.raises(ValueError): + self.plotmethod(colors='k', cmap='RdBu') + @pytest.mark.slow class TestContourf(Common2dMixin, PlotTestCase):