id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type 735523592,MDU6SXNzdWU3MzU1MjM1OTI=,4562,Cannot plot multiindexed (stacked) coordinate as hue variable ,20617032,open,0,,,7,2020-11-03T17:53:01Z,2021-11-16T23:39:09Z,,NONE,,,,"``` import numpy as np import pandas as pd import xarray as xr data = np.random.rand(50,5) x_idx = np.linspace(0, 50) mi_idx1 = ['a','b','c','d','e'] mi_idx2 = [1,2,3,4,5] mi = pd.MultiIndex.from_arrays([mi_idx1,mi_idx2], names=['mi_idx1', 'mi_idx2']) coords = { 'x': x_idx, 'mi': mi } da = xr.DataArray(data, coords=coords, dims = ['x', 'mi']) da.plot(hue='mi') ``` It appears since version 0.16.0, that plotting with a multindex coordinate as a hue dimension no longer works. In version 0.15.1 I get a plot like this: ![xarray_issue](https://user-images.githubusercontent.com/20617032/98021886-ba7f6b00-1db9-11eb-80af-bea7540cc785.png) However, when upgrading to 0.16.0 or 0.16.1 I get the following traceback: ``` ValueError Traceback (most recent call last) in 19 da = xr.DataArray(data, coords=coords, dims = ['x', 'mi']) 20 ---> 21 da.plot(hue='mi') ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\plot.py in __call__(self, **kwargs) 444 445 def __call__(self, **kwargs): --> 446 return plot(self._da, **kwargs) 447 448 # we can't use functools.wraps here since that also modifies the name / qualname ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\plot.py in plot(darray, row, col, col_wrap, ax, hue, rtol, subplot_kws, **kwargs) 198 kwargs[""ax""] = ax 199 --> 200 return plotfunc(darray, **kwargs) 201 202 ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\plot.py in line(darray, row, col, figsize, aspect, size, ax, hue, x, y, xincrease, yincrease, xscale, yscale, xticks, yticks, xlim, ylim, add_legend, _labels, *args, **kwargs) 293 294 ax = get_axis(figsize, size, aspect, ax) --> 295 xplt, yplt, hueplt, xlabel, ylabel, hue_label = _infer_line_data(darray, x, y, hue) 296 297 # Remove pd.Intervals if contained in xplt.values and/or yplt.values. ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\plot.py in _infer_line_data(darray, x, y, hue) 66 67 if y is None: ---> 68 xname, huename = _infer_xy_labels(darray=darray, x=x, y=hue) 69 xplt = darray[xname] 70 if xplt.ndim > 1: ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\utils.py in _infer_xy_labels(darray, x, y, imshow, rgb) 378 y, x = darray.dims 379 elif x is None: --> 380 _assert_valid_xy(darray, y, ""y"") 381 x = darray.dims[0] if y == darray.dims[1] else darray.dims[1] 382 elif y is None: ~\anaconda3\envs\datanalysis\lib\site-packages\xarray\plot\utils.py in _assert_valid_xy(darray, xy, name) 410 if xy not in valid_xy: 411 valid_xy_str = ""', '"".join(sorted(valid_xy)) --> 412 raise ValueError(f""{name} must be one of None, '{valid_xy_str}'"") 413 414 ValueError: y must be one of None, 'mi_idx1', 'mi_idx2', 'x' ``` Setting x='x' does not fix the problem
Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: English_United States.1252 libhdf5: 1.10.4 libnetcdf: 4.7.3 xarray: 0.16.0 pandas: 1.0.5 numpy: 1.18.5 scipy: 1.5.0 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.2.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: 2.20.0 distributed: 2.20.0 matplotlib: 3.2.2 cartopy: None seaborn: 0.10.1 numbagg: None pint: 0.16.1 setuptools: 49.2.0.post20200714 pip: 20.1.1 conda: None pytest: 5.4.3 IPython: 7.16.1 sphinx: 3.1.2
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/4562/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,,13221727,issue