Skip to content

Commit caef62a

Browse files
author
dcherian
committed
bugfix: facetgrid now uses hue_style
1 parent f2704f8 commit caef62a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

xarray/plot/dataset_plot.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def _infer_scatter_meta_data(ds, x, y, hue, hue_style, add_colorbar,
2525

2626
dims_coords = set(list(ds.coords) + list(ds.dims))
2727
if hue is not None and hue not in dims_coords:
28-
raise ValueError(hue + ' must be either one of ({0:s})'
29-
''.format(', '.join(dims_coords)))
28+
raise ValueError('hue must be one of ({0:s}) but is {hue}'
29+
'instead.'.format(', '.join(dims_coords)), hue)
3030

3131
if hue:
3232
hue_is_numeric = (_ensure_numeric(ds[hue].values)
@@ -195,7 +195,8 @@ def scatter(ds, x, y, hue=None, hue_style=None, col=None, row=None,
195195
g = FacetGrid(data=ds, col=col, row=row, col_wrap=col_wrap,
196196
sharex=sharex, sharey=sharey, figsize=figsize,
197197
aspect=aspect, size=size, subplot_kws=subplot_kws)
198-
return g.map_scatter(x=x, y=y, hue=hue, add_colorbar=add_colorbar,
198+
return g.map_scatter(x=x, y=y, hue=hue, hue_style=hue_style,
199+
add_colorbar=add_colorbar,
199200
add_legend=add_legend, **kwargs)
200201

201202
figsize = kwargs.pop('figsize', None)

xarray/tests/test_plot.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,16 @@ def test_datetime_hue(self, hue_style):
18611861
ds2['hue'] = pd.timedelta_range('-1D', periods=4, freq='D')
18621862
ds2.plot.scatter(x='A', y='B', hue='hue', hue_style=hue_style)
18631863

1864+
@pytest.mark.parametrize('hue_style, map_type',
1865+
(['discrete', list],
1866+
['continuous', mpl.collections.PathCollection]))
1867+
def test_facetgrid_hue_style(self, hue_style, map_type):
1868+
g = self.ds.plot.scatter(x='A', y='B', row='row', col='col', hue='hue',
1869+
hue_style=hue_style)
1870+
# for 'discrete' a list is appended to _mappables
1871+
# for 'continuous', should be single PathCollection
1872+
assert type(g._mappables[-1]) == map_type
1873+
18641874
def test_non_numeric_legend(self):
18651875
ds2 = self.ds.copy()
18661876
ds2['hue'] = ['a', 'b', 'c', 'd']

0 commit comments

Comments
 (0)