Skip to content

Commit 821479d

Browse files
authored
improve the error message for invalid hue names (#5060)
1 parent 483f751 commit 821479d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

xarray/plot/plot.py

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def _infer_line_data(darray, x, y, hue):
6565
raise ValueError("For 2D inputs, please specify either hue, x or y.")
6666

6767
if y is None:
68+
if hue is not None:
69+
_assert_valid_xy(darray, hue, "hue")
6870
xname, huename = _infer_xy_labels(darray=darray, x=x, y=hue)
6971
xplt = darray[xname]
7072
if xplt.ndim > 1:

xarray/tests/test_plot.py

+9
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ def test_line_plot_along_1d_coord(self):
267267
line = da.plot(y="time", hue="x")[0]
268268
assert_array_equal(line.get_ydata(), da.coords["time"].values)
269269

270+
def test_line_plot_wrong_hue(self):
271+
da = xr.DataArray(
272+
data=np.array([[0, 1], [5, 9]]),
273+
dims=["x", "t"],
274+
)
275+
276+
with pytest.raises(ValueError, match="hue must be one of"):
277+
da.plot(x="t", hue="wrong_coord")
278+
270279
def test_2d_line(self):
271280
with raises_regex(ValueError, "hue"):
272281
self.darray[:, :, 0].plot.line()

0 commit comments

Comments
 (0)