Skip to content

Commit 1dfad9f

Browse files
committed
improve ds to da wrapper
1 parent 5f57f5c commit 1dfad9f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

xarray/plot/dataset_plot.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -674,24 +674,27 @@ def plotmethod(self, *args, **kwargs):
674674
setattr(_Dataset_PlotMethods, plotmethod.__name__, plotmethod)
675675

676676

677-
def _temp_dataarray(ds, y, kwargs):
677+
def _temp_dataarray(ds, y, args, kwargs):
678678
"""Create a temporary datarray with extra coords."""
679679
from ..core.dataarray import DataArray
680680

681681
# Base coords:
682682
coords = dict(ds.coords)
683683

684684
# Add extra coords to the DataArray:
685-
coords.update(
686-
{v: ds[v] for v in kwargs.values() if ds.data_vars.get(v) is not None}
687-
)
685+
all_args = args + tuple(kwargs.values())
686+
coords.update({v: ds[v] for v in all_args if ds.data_vars.get(v) is not None})
687+
688+
# The dataarray has to include all the dims. Broadcast to that shape
689+
# and add the additional coords:
690+
_y = ds[y].broadcast_like(ds)
688691

689-
return DataArray(ds[y], coords=coords)
692+
return DataArray(_y, coords=coords)
690693

691694

692695
@_attach_to_plot_class
693-
def line(ds, y=None, **kwargs):
696+
def line(ds, x, y, *args, **kwargs):
694697
"""Line plot Dataset data variables against each other."""
695-
da = _temp_dataarray(ds, y, kwargs)
698+
da = _temp_dataarray(ds, y, args, kwargs)
696699

697-
return da.plot.line(**kwargs)
700+
return da.plot.line(x, *args, **kwargs)

0 commit comments

Comments
 (0)