Skip to content

Commit 9accae0

Browse files
Zac-HDshoyer
authored andcommitted
Fix RGB imshow with X or Y dim of size one (#1967)
1 parent 870e4ea commit 9accae0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Bug fixes
6464
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
6565
- Fix kwarg `colors` clashing with auto-inferred `cmap` (:issue:`1461`)
6666
By `Deepak Cherian <https://github.com/dcherian>`_.
67+
- Fix :py:func:`~xarray.plot.imshow` error when passed an RGB array with
68+
size one in a spatial dimension.
69+
By `Zac Hatfield-Dodds <https://github.com/Zac-HD>`_.
6770

6871
.. _whats-new.0.10.1:
6972

xarray/plot/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def _infer_xy_labels_3d(darray, x, y, rgb):
296296
assert rgb is not None
297297

298298
# Finally, we pick out the red slice and delegate to the 2D version:
299-
return _infer_xy_labels(darray.isel(**{rgb: 0}).squeeze(), x, y)
299+
return _infer_xy_labels(darray.isel(**{rgb: 0}), x, y)
300300

301301

302302
def _infer_xy_labels(darray, x, y, imshow=False, rgb=None):

xarray/tests/test_plot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,11 @@ def test_imshow_rgb_values_in_valid_range(self):
11971197
assert out.dtype == np.uint8
11981198
assert (out[..., :3] == da.values).all() # Compare without added alpha
11991199

1200+
def test_regression_rgb_imshow_dim_size_one(self):
1201+
# Regression: https://github.com/pydata/xarray/issues/1966
1202+
da = DataArray(easy_array((1, 3, 3), start=0.0, stop=1.0))
1203+
da.plot.imshow()
1204+
12001205

12011206
class TestFacetGrid(PlotTestCase):
12021207
def setUp(self):

0 commit comments

Comments
 (0)