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 Xarray Plotting Routines #760

Merged
merged 11 commits into from
Apr 17, 2024
Merged

Support Xarray Plotting Routines #760

merged 11 commits into from
Apr 17, 2024

Conversation

philipc2
Copy link
Member

@philipc2 philipc2 commented Apr 9, 2024

Closes #759

Overview

  • Adds support to call Xarray plotting methods through the UxDataArray and UxDataset plotting accessors

Expected Usage

import uxarray as ux

grid_path = "/path/to/grid.nc"
data_path = "/path/to/data.nc"

uxds = ux.open_dataset(grid_path, data_path)

# call Xarray Plotting Methods
uxds['var'].plot.hist()
uxds['var'].plot.line()
# and so on

@philipc2 philipc2 self-assigned this Apr 9, 2024
@philipc2
Copy link
Member Author

philipc2 commented Apr 9, 2024

Examples

uxds['v1'][0][0].plot.hist(bins=60, figsize=(10, 5))

image

uxds['v1'][0].mean("n_node").plot.line("o--", figsize=(10, 5))

image

@philipc2
Copy link
Member Author

philipc2 commented Apr 9, 2024

Update the .plot accessor docstring to mention the use of Xarray functionality.

@philipc2
Copy link
Member Author

I have fixed the matplotlib backend issue we were encountering. Previously, if we would call backend='matplotlib' for any of our HoloViz functionality, it would set the backend used in the matplotlib package to agg, which differs from the default one in xarray, which is set to "module://matplotlib_inline.backend_inline"

With the changes, we the xarray methods no longer have any issues when backend='matplotlib' is set for any of our HoloViz functionality

# holoviews with a matplotlib backend
uxds['t2m'].plot(backend='matplotlib')

# xarray method, would not render before, but with the change it works
uxds['t2m'].plot.hist()

@philipc2 philipc2 added this to the Visualization milestone Apr 17, 2024
@philipc2 philipc2 merged commit a85db05 into main Apr 17, 2024
15 checks passed
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 this pull request may close these issues.

Support Xarray Plotting Routines
1 participant