home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 628089013

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
628089013 MDU6SXNzdWU2MjgwODkwMTM= 4115 DataArray.plot.line color kwarg 6588826 closed 0     2 2020-06-01T01:14:17Z 2020-06-01T19:43:54Z 2020-06-01T19:43:54Z NONE      

matplotlib.colors throws ValueError when a list of colors is passed to xr.DataArray.plot.line

MCVE Code Sample

```python import matplotlib import matplotlib.colors import matplotlib.cm import xarray as xr import numpy as np

data = np.random.random((10,10)) x = np.arange(0,1.0,0.1) y = np.arange(0,100,10.0)

norm = matplotlib.colors.Normalize(vmin=y.min(),vmax=y.max()) cmapper = matplotlib.cm.ScalarMappable(norm=norm,cmap=matplotlib.cm.viridis).to_rgba

da = xr.DataArray(data,dims=['x','y'],coords={'x':x,'y':y})

da.plot.line(x='x',color=cmapper(da.y.values)) #throws ValueError in matplotlib/colors.py

da.to_pandas().plot(color=cmapper(da.y.values)) ```

Expected Output

Problem Description

I need to be able to map coordinate values to colors so that data plotted from different arrays are always aligned in colorspace. Depending on the data, specific y-values may be missing so a simple color cycle doesn't work here unfortunately. Passing a list of colors to pandas.plot seems to work but not for xarray.plot. While the obvious workaround is to cast to pandas, is there something I can do to make this work for xarray?

Versions

Output of <tt>xr.show_versions()</tt> INSTALLED VERSIONS ------------------ commit: None python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 22:45:16) [Clang 9.0.1 ] python-bits: 64 OS: Darwin OS-release: 19.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.3 xarray: 0.15.1 pandas: 1.0.3 numpy: 1.18.4 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.1.1.1 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.12.0 distributed: None matplotlib: 3.2.1 cartopy: None seaborn: 0.10.1 numbagg: None setuptools: 47.1.0.post20200528 pip: 20.1.1 conda: None pytest: None IPython: 7.13.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/4115/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

  • 0 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 0.599ms · About: xarray-datasette