holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.13k stars 109 forks source link

hvplot expects xarray coordinate variable and dimension name to be the same? #329

Closed rsignell-usgs closed 4 years ago

rsignell-usgs commented 5 years ago

This fails:

import xarray as xr
import hvplot.xarray

url = 'http://tds.glos.us/thredds/dodsC/glos/glcfs/huron/fcfmrc-3d/Lake_Huron_-_3D_best.ncd'
ds  = xr.open_dataset(url)
ds.temp.hvplot.quadmesh(x='lon', y='lat', rasterize=True)

with a cryptic error:

ValueError: can only convert an array of size 1 to a Python scalar

By trial and error, I discovered that the vertical coordinate name is sigma, but the dimension name of sigma is nsigma: sigma(nsigma).

If I simply rename the dimension nsigma to sigma, everything works as expected:

ds = ds.rename({'nsigma':'sigma'})

See https://nbviewer.jupyter.org/gist/rsignell-usgs/d5eee45716933297c978318e2a147fb6

philippjfr commented 4 years ago

I think the correct way to handle this is to set sigma as an index: .set_index({'nsigma': 'sigma'}). I'll see if we can automate that though.