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

Support using xarray non-dimensioned coordinates as explicit kdims. #6131

Open
alcrene opened this issue Feb 26, 2024 · 0 comments · May be fixed by #6132
Open

Support using xarray non-dimensioned coordinates as explicit kdims. #6131

alcrene opened this issue Feb 26, 2024 · 0 comments · May be fixed by #6132

Comments

@alcrene
Copy link

alcrene commented Feb 26, 2024

This is somewhat a complement issue to the treatment of xarray non-dimensioned coordinates #5214 .
That issue concerned the behaviour non-dimensioned with auto-populated widgets. With good reason non-dimensioned coordinates are not treated as kdims in that case.

However I think it would still be very useful if they could be used with kdims when explicitely specified by a user. Consider the following example from the xarray docs:

In [65]: ds.coords
Out[65]: 
Coordinates:
    lat             (x, y) float64 42.25 42.21 42.63 42.59
    lon             (x, y) float64 -99.83 -99.32 -99.79 -99.23
  * time            (time) datetime64[ns] 2014-09-06 2014-09-07 2014-09-08
    reference_time  datetime64[ns] 2014-09-05
    day             (time) int64 6 7 8

Here 'lat' and 'lon' are non-dimensioned coordinates, yet I would think that it makes sense to want to use them as kdims to a scatter plot or heatmap.

As another example, consider a simulation that has multiple variants of its time axis:

  • simulator step (int)
  • simulation time (float)
  • real-world time (float)

Only one of this can be a dimensioned coordinate in the DataArray, yet all of them could sensibly be used as a plotting axis.

Finally, it may be worth noting that plotting is one of the explicit intentions for non-dimensioned coordinates according to the docs I linked above.

Describe the solution you'd like

Given an xarray DataArray,

da = xr.DataArray(np.arange(6).reshape(6,1), dims=["x", "stat"], coords={"x": np.arange(6), "stat": ["mean"], "x2": ('x', np.arange(6)/6)})

it is very easy to plot using dimensioned coordinates as kdims:

hv.Curve(da, kdims="x", vdims="stat")

I would like the same to be true for non-dimensioned coordinates

hv.Curve(da, kdims="x2", vdims="stat")

Workaround

One approach that already works today is to first convert to a dataframe

hv.Curve(da.to_dataframe(name="mean"), kdims="x2", vdims="mean")

This isn’t too bad (even though the vdim name needs to be repeated), but it still feels like xarray’s annotation abilities (here to specify alternative axes) are being wasted.

@hoxbro hoxbro linked a pull request Feb 26, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant