diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index f244e865263..5bceba14bec 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -8,7 +8,7 @@ from .utils import ( _infer_xy_labels, _process_cmap_cbar_kwargs, import_matplotlib_pyplot, label_from_attrs) - +import xarray as xr # Overrides axes.labelsize, xtick.major.size, ytick.major.size # from mpl.rcParams _FONTSIZE = 'small' @@ -337,9 +337,13 @@ def _finalize_grid(self, *axlabels): self._finalized = True def add_legend(self, **kwargs): + if isinstance(self._hue_var, xr.DataArray): + labels = self._hue_var.values + else: + labels = self._hue_var figlegend = self.fig.legend( handles=self._mappables[-1], - labels=list(self._hue_var.values), + labels=list(labels), title=self._hue_label, loc="center right", **kwargs) diff --git a/xarray/tutorial.py b/xarray/tutorial.py index 96f548a8766..608f5c5270d 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -126,4 +126,3 @@ def scatter_example_dataset(): ds.B.attrs['units'] = 'Bunits' return ds -