Skip to content

Commit ad8fa8a

Browse files
committed
don't lose first group + fix line
1 parent 6263128 commit ad8fa8a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

xarray/plot/facetgrid.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import numpy as np
66

77

8-
from ..core.utils import peek_at
98
from ..core.formatting import format_item
109
from .utils import (
1110
_infer_xy_labels,
@@ -401,8 +400,12 @@ def map_groupby(
401400
func_kwargs.update({"add_colorbar": False, "add_labels": False})
402401

403402
# Get x, y labels for the first subplot
403+
grouped = self.data
404+
first_group = grouped._obj.isel(
405+
**{grouped._group_dim: grouped._group_indices[0]}
406+
).squeeze()
404407
x, y = _infer_xy_labels(
405-
darray=peek_at(self.data._iter_grouped())[0],
408+
darray=first_group,
406409
x=x,
407410
y=y,
408411
imshow=func.__name__ == "imshow",
@@ -425,9 +428,17 @@ def map_groupby_line(
425428
):
426429
from .plot import _infer_line_data
427430

431+
grouped = self.data
432+
first_group = grouped._obj.isel(
433+
**{grouped._group_dim: grouped._group_indices[0]}
434+
).squeeze()
435+
_, _, hueplt, xlabel, ylabel, huelabel = _infer_line_data(
436+
darray=first_group, x=x, y=y, hue=hue
437+
)
438+
428439
for (_, subset), ax in zip(self.data, self.axes.flat):
429440
mappable = func(
430-
subset,
441+
subset.squeeze(),
431442
x=x,
432443
y=y,
433444
ax=ax,
@@ -438,10 +449,6 @@ def map_groupby_line(
438449
)
439450
self._mappables.append(mappable)
440451

441-
_, _, hueplt, xlabel, ylabel, huelabel = _infer_line_data(
442-
darray=peek_at(self.data._iter_grouped())[0], x=x, y=y, hue=hue
443-
)
444-
445452
self._hue_var = hueplt
446453
self._hue_label = huelabel
447454
self._finalize_grid(xlabel, ylabel)

0 commit comments

Comments
 (0)