diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 04b06fff221..863451b6bd0 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -73,6 +73,9 @@ Bug fixes special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar()` (:issue:`7928`, :pull:`8084`). By `Kai Mühlbauer `_. +- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments + (:issue:`7552`, :pull:`8174`). + By `Wiktor Kraśnicki `_. Documentation ~~~~~~~~~~~~~ diff --git a/xarray/plot/dataarray_plot.py b/xarray/plot/dataarray_plot.py index 8afd87ea64a..54f3c657b6c 100644 --- a/xarray/plot/dataarray_plot.py +++ b/xarray/plot/dataarray_plot.py @@ -264,7 +264,9 @@ def plot( -------- xarray.DataArray.squeeze """ - darray = darray.squeeze().compute() + darray = darray.squeeze( + d for d, s in darray.sizes.items() if s == 1 and d not in (row, col, hue) + ).compute() plot_dims = set(darray.dims) plot_dims.discard(row) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index d80445af329..6cc061a7ee5 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -729,6 +729,13 @@ def test_labels_with_units_with_interval(self, dim) -> None: expected = "dim_0_bins_center [m]" assert actual == expected + def test_multiplot_over_length_one_dim(self) -> None: + a = easy_array((3, 1, 1, 1)) + d = DataArray(a, dims=("x", "col", "row", "hue")) + d.plot(col="col") + d.plot(row="row") + d.plot(hue="hue") + class TestPlot1D(PlotTestCase): @pytest.fixture(autouse=True)