home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 528062816

This data as json

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
528062816 MDU6SXNzdWU1MjgwNjI4MTY= 3571 Binned coordinates (pd.Interval) not plottable on the y-axis. 1186928 closed 0     1 2019-11-25T12:44:40Z 2020-01-22T21:09:39Z 2020-01-22T21:09:39Z CONTRIBUTOR      

Minimal Code Sample

```python import numpy as np import xarray as xr import matplotlib.pyplot as plt

create fake data

data = xr.DataArray(np.random.rand(101)).rename('data')

group by bins and compute sum

bins = np.linspace(0, 1, 11) data = data.groupby_bins(data, bins).sum()

plot group means

data.plot() # works data.plot(x='data_bins') # works plt.plot((bins[:-1]+bins[1:])/2, data) # works

plot with axes transposed

data.plot(y='data_bins') # TypeError data.plot.line(y='data_bins') # TypeError plt.plot(data, (bins[:-1]+bins[1:])/2) # workaround ```

Expected Output

I would like to plot binned data (produced with groupby_bins) with transposed axes, i.e. data on the x-axis, and bins on the y-axis.

Problem Description

Attempting to plot using an array of pd.Interval on the y-axis yields the following TypeError. The error message reports data should be numeric, dates or pd.Interval, which they are.

Traceback (most recent call last): File "./groupbybug.py", line 19, in <module> data.plot(y='data_bins') # TypeError File "~/.local/lib/python3.7/site-packages/xarray/plot/plot.py", line 465, in __call__ return plot(self._da, **kwargs) File "~/.local/lib/python3.7/site-packages/xarray/plot/plot.py", line 202, in plot return plotfunc(darray, **kwargs) File "~/.local/lib/python3.7/site-packages/xarray/plot/plot.py", line 323, in line _ensure_plottable(xplt_val, yplt_val) File "~/.local/lib/python3.7/site-packages/xarray/plot/utils.py", line 512, in _ensure_plottable "Plotting requires coordinates to be numeric " TypeError: Plotting requires coordinates to be numeric or dates of type np.datetime64, datetime.datetime, cftime.datetime or pd.Interval.

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.4 (default, Oct 4 2019, 06:57:26) [GCC 9.2.0] python-bits: 64 OS: Linux OS-release: 4.19.84-1-MANJARO machine: x86_64 processor: byteorder: little LC_ALL: None LANG: fr_CH.utf8 LOCALE: fr_CH.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.2 xarray: 0.14.1 pandas: 0.25.2 numpy: 1.17.3 scipy: 1.3.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: 1.1.0 cfgrib: None iris: None bottleneck: None dask: 2.5.2 distributed: 0+untagged.1.gd096901.dirty matplotlib: 3.1.1 cartopy: 0.17.0 seaborn: None numbagg: None setuptools: 41.2.0 pip: 19.2.3 conda: None pytest: 5.2.1 IPython: 7.9.0 sphinx: 2.2.1
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3571/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.806ms · About: xarray-datasette