From 5d78fb201d3fe62542162eac67fc955155fc6059 Mon Sep 17 00:00:00 2001 From: dcherian Date: Sun, 29 Mar 2020 07:19:08 -0600 Subject: [PATCH] facetgrid: Ensure that colormap params are only determined once. Fixes #3569 --- doc/whats-new.rst | 3 ++- xarray/plot/facetgrid.py | 2 +- xarray/plot/plot.py | 5 ++++- xarray/plot/utils.py | 10 +++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index c70dfd4f3f6..e027a07a03a 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -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 `_ - +- Ensure that colormap parameters are only determined once for FacetGrid plots. + (:issue:`3569`). By `Deepak Cherian `_ Documentation ~~~~~~~~~~~~~ diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index 4f3268c1203..b679b80bcf6 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -273,7 +273,7 @@ def map_dataarray(self, func, x, y, **kwargs): # None is the sentinel value if d is not None: subset = self.data.loc[d] - mappable = func(subset, x=x, y=y, ax=ax, **func_kwargs) + mappable = func(subset, x=x, y=y, ax=ax, **func_kwargs, _is_facetgrid=True) self._mappables.append(mappable) self._finalize_grid(x, y) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index 302cac05b05..487dd33dd3e 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -692,7 +692,10 @@ def newplotfunc( _ensure_plottable(xplt, yplt) cmap_params, cbar_kwargs = _process_cmap_cbar_kwargs( - plotfunc, zval.data, **locals() + plotfunc, + zval.data, + **locals(), + _is_facetgrid=kwargs.pop("_is_facetgrid", False), ) if "contour" in plotfunc.__name__: diff --git a/xarray/plot/utils.py b/xarray/plot/utils.py index e6c15037cb8..f4e6b6527a3 100644 --- a/xarray/plot/utils.py +++ b/xarray/plot/utils.py @@ -153,6 +153,7 @@ def _determine_cmap_params( levels=None, filled=True, norm=None, + _is_facetgrid=False, ): """ Use some heuristics to set good defaults for colorbar and range. @@ -727,6 +728,7 @@ def _process_cmap_cbar_kwargs( colors=None, cbar_kwargs: Union[Iterable[Tuple[str, Any]], Mapping[str, Any]] = None, levels=None, + _is_facetgrid=False, **kwargs, ): """ @@ -773,6 +775,12 @@ def _process_cmap_cbar_kwargs( cmap_args = getfullargspec(_determine_cmap_params).args cmap_kwargs.update((a, kwargs[a]) for a in cmap_args if a in kwargs) - cmap_params = _determine_cmap_params(**cmap_kwargs) + if not _is_facetgrid: + cmap_params = _determine_cmap_params(**cmap_kwargs) + else: + cmap_params = { + k: cmap_kwargs[k] + for k in ["vmin", "vmax", "cmap", "extend", "levels", "norm"] + } return cmap_params, cbar_kwargs