Skip to content

Commit c439432

Browse files
krokosikmathausedcherian
authored
Exclude dimensions used in faceting from squeeze (#8174)
* 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]>
1 parent babe9ff commit c439432

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Bug fixes
7373
special case ``NaT`` handling in :py:meth:`~core.accessor_dt.DatetimeAccessor.isocalendar()`
7474
(:issue:`7928`, :pull:`8084`).
7575
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
76+
- Calling plot with kwargs ``col``, ``row`` or ``hue`` no longer squeezes dimensions passed via these arguments
77+
(:issue:`7552`, :pull:`8174`).
78+
By `Wiktor Kraśnicki <https://github.com/wkrasnicki>`_.
7679

7780
Documentation
7881
~~~~~~~~~~~~~

xarray/plot/dataarray_plot.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ def plot(
264264
--------
265265
xarray.DataArray.squeeze
266266
"""
267-
darray = darray.squeeze().compute()
267+
darray = darray.squeeze(
268+
d for d, s in darray.sizes.items() if s == 1 and d not in (row, col, hue)
269+
).compute()
268270

269271
plot_dims = set(darray.dims)
270272
plot_dims.discard(row)

xarray/tests/test_plot.py

+7
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,13 @@ def test_labels_with_units_with_interval(self, dim) -> None:
729729
expected = "dim_0_bins_center [m]"
730730
assert actual == expected
731731

732+
def test_multiplot_over_length_one_dim(self) -> None:
733+
a = easy_array((3, 1, 1, 1))
734+
d = DataArray(a, dims=("x", "col", "row", "hue"))
735+
d.plot(col="col")
736+
d.plot(row="row")
737+
d.plot(hue="hue")
738+
732739

733740
class TestPlot1D(PlotTestCase):
734741
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)