Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude dimensions used in faceting from squeeze #8174

Merged
merged 8 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ Bug fixes
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar()`
(:issue:`7928`, :pull:`8084`).
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments
(:issue:`7552`, :pull:`8174`).
By `Wiktor Kraśnicki <https://github.com/wkrasnicki>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion xarray/plot/dataarray_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,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)
Expand Down
Loading