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

Axes flipped when plotting an xarray.DataArray #668

Closed
maawoo opened this issue Oct 21, 2021 · 4 comments
Closed

Axes flipped when plotting an xarray.DataArray #668

maawoo opened this issue Oct 21, 2021 · 4 comments
Labels
type: bug Something isn't working
Milestone

Comments

@maawoo
Copy link

maawoo commented Oct 21, 2021

ALL software version info

  • Python 3.9.7 conda environment on CentOS 7
  • hvplot=0.7.3
  • holoviews=1.14.5
  • datashader=0.13
  • xarray=0.19

hvplot imported as import hvplot.xarray

Description of expected behavior and the observed behavior

Expected:
Plot created from a 2-dimensional xarray.DataArray is by default plotted similarly to xarray's matplotlib wrapper, i.e. same orientation of axes.

Observed:
x and y axes are flipped

Complete, minimal, self-contained example code that reproduces the issue

Can't provide a self-contained example but hopefully the following helps.

The xarray.DataArray with UTM x and y coordinates:
grafik

Plot using xarray's matplotlib wrapper showing the correct orientation:

ds.plot(cmap='viridis', figsize=(12, 10))

grafik

Plots using hvplot (same problem with .hvplot and .hvplot.image) with some flippin' going on:

ds.hvplot(cmap='viridis', height=600, width=800) 
ds.hvplot.image(cmap='viridis', height=600, width=800)

grafik

@maawoo
Copy link
Author

maawoo commented Oct 21, 2021

Okay solved it myself by passing x='x', y='y'. I misunderstood this earlier and tried passing x=ds.x, y=ds.y instead, which doesn't work. Shouldn't x='x', y='y' be the default, however?

@philippjfr
Copy link
Member

Thanks for the issue!

Shouldn't x='x', y='y' be the default, however?

I'd prefer not to add any special case logic looking for specific coordinate names so definitely -1 on that. However since xarray somehow figures out the appropriate axis ordering in this case we will have to take another look at how they do it compared to how we do it.

@philippjfr philippjfr added the type: bug Something isn't working label Oct 21, 2021
@philippjfr philippjfr added this to the 0.8 milestone Oct 21, 2021
@maximlt
Copy link
Member

maximlt commented Mar 25, 2022

xarray reverses the DataArray dims, it considers the x-axis as dims[1] and and the y-axis as dims[0].
image

This is defined here:
https://github.com/pydata/xarray/blob/f8bae5974ee2c3f67346298da12621af4cae8cf8/xarray/plot/utils.py#L376

In the example provided by the OP the DataArray dimensions are ('y', 'x') so when reversed they are "correctly" displayed. I don't know if this inversion done by xarray lies on some sort of convention but without any more context (no attributes parsing or anything else), it seems to me it's a little too arbitrary, and anyway easily handled at the hvplot level with x='x', y='y'. I'm going to close this issue then, if this happens to rely on a convention I was not aware please let me know and I'll happily implement xarray's behavior.

@maximlt maximlt closed this as completed Mar 25, 2022
@maximlt
Copy link
Member

maximlt commented Mar 28, 2022

@philippjfr should we reproduce what xarray does, as asked in this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants