Skip to content

Commit

Permalink
Exclude dimensions used in faceting from squeeze (#8174)
Browse files Browse the repository at this point in the history
* Exclude dimensions used in faceting from squeeze

* Add unit test for facetting singleton dim

* Add bug fix to changelog

* Move test to proper class

* Update doc/whats-new.rst

* Apply suggestions from code review

* Update doc/whats-new.rst

---------

Co-authored-by: Mathias Hauser <[email protected]>
Co-authored-by: Deepak Cherian <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2023
1 parent babe9ff commit c439432
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 @@ -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)
Expand Down

0 comments on commit c439432

Please sign in to comment.