Skip to content
forked from pydata/xarray

Commit

Permalink
facetgrid: Ensure that colormap params are only determined once.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 29, 2020
1 parent 1416d5a commit 5d78fb2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
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>`_

- Ensure that colormap parameters are only determined once for FacetGrid plots.
(:issue:`3569`). By `Deepak Cherian <https://github.com/dcherian>`_

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/plot/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__:
Expand Down
10 changes: 9 additions & 1 deletion xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
):
"""
Expand Down Expand Up @@ -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

0 comments on commit 5d78fb2

Please sign in to comment.