Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting of labelled data fails #5762

Closed
dschwoerer opened this issue Sep 3, 2021 · 3 comments · May be fixed by #5763
Closed

Plotting of labelled data fails #5762

dschwoerer opened this issue Sep 3, 2021 · 3 comments · May be fixed by #5763

Comments

@dschwoerer
Copy link
Contributor

What happened:
Xarray has some assumption what is or is not plottable. Xarray should not do that, and just ask the plotting library, if it actually can.

What you expected to happen:
No additional checking, just plot it.

If something cannot be plotted, matplotlib (or whatever backend is used) will anyway check, and know better.

Minimal Complete Verifiable Example:

import xarray as xr
import matplotlib.pyplot as plt

da = xr.DataArray(data=[1, 2], coords={"x": ["abc", "cde"]}, dims="x")
print(da)
try:
    da.plot()
except TypeError:
    plt.plot(da.x, da)
    print("But it is possible")
plt.show()

Anything else we need to know?:
I can submit a PR to remove _ensure_plottable

Environment:

Output of xr.show_versions() INSTALLED VERSIONS ------------------ commit: fcebe5e python: 3.9.7 (default, Aug 30 2021, 00:00:00) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] python-bits: 64 OS: Linux OS-release: 5.13.12-200.fc34.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.3

xarray: 0.18.2
pandas: 1.2.5
numpy: 1.20.1
scipy: 1.6.2
netCDF4: 1.5.5.1
pydap: None
h5netcdf: None
h5py: 3.1.0
Nio: None
zarr: None
cftime: 1.4.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 2021.08.1
distributed: None
matplotlib: 3.4.3
cartopy: None
seaborn: None
numbagg: None
pint: 0.16.1
setuptools: 54.2.0
pip: 21.0.1
conda: None
pytest: 6.2.2
IPython: 7.20.0
sphinx: 3.4.3

@Illviljan
Copy link
Contributor

Illviljan commented Sep 3, 2021

I think if you try out 0.19 you'll find that this works, see #5464. I just tried your example with master main and it works.

Though I'm not opposed to removing it, it makes sense to me to just trust the backend will do its job. But there's always some weird edge case that doesn't always make it that easy.

@dschwoerer
Copy link
Contributor Author

I tried it with master, and it failed. Trying with main worked :-D

I think there will be cases where the data is not suitable for plotting, where the new error will be less clear than the old one, but I still think that would be overall an improvement.

@headtr1ck
Copy link
Collaborator

Closing this issue in favor of #7593 since the provided MVCE in this issue now works.

@headtr1ck headtr1ck closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants