You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a PhD student in climate science, and love proplot! But I would love to use it from xarray using an accessor. That might look like this:
So you can toy with the data yourself, I used the Xarray tutorial air temperature dataset for an "example" of sorts. The environment needs both pooch (```conda install pooch``) and Xarray installed.
importxarrayasxrairtemps=xr.tutorial.open_dataset("air_temperature")
airtemp1D=airtemps.mean(dim=['lat','lon']).air# example of 1D (time)airtemp2D=airtemps.isel(time=0).air# example of 2D (lat,lon)airtemps3D=airtemps.air# example of 3D (time,lat,lon)
Make plotting simple graphs in proplot an accessor to Xarray:
importproplotaspplt@xr.register_dataarray_accessor("proplot")classProPlotAccessor:
def__init__(self, xarray_obj):
self=xarray_objdefplot1D(self):
fig,ax=pplt.subplots(nrows=1,ncols=1)
ax.plot(self,color='k')
defplot2D(self):
fig,ax=pplt.subplots(nrows=1,ncols=1)
ax.contourf(self,cmap='viridis')
defplot(self):
iflen(self.dims) ==1: # if data is 1Dreturnself.plot1D()
eliflen(self.dims) ==2: # if data is 2Dreturnself.plot2D()
else:
raiseValueError("Data is not 1D or 2D")
Test the accessor on the Xarray tutorial data with different dimensions:
airtemps1D.proplot.plot()
airtemps2D.proplot.plot()
I think this would be impactful because it would make it easier for those in the climate science space who use Xarray to get their feet wet with proplot, moving away from matplotlib. I'd be happy to collaborate on this effort if wanted/needed!
I am a PhD student in climate science, and love proplot! But I would love to use it from xarray using an accessor. That might look like this:
So you can toy with the data yourself, I used the Xarray tutorial air temperature dataset for an "example" of sorts. The environment needs both pooch (```conda install pooch``) and Xarray installed.
Make plotting simple graphs in proplot an accessor to Xarray:
Test the accessor on the Xarray tutorial data with different dimensions:
I think this would be impactful because it would make it easier for those in the climate science space who use Xarray to get their feet wet with proplot, moving away from matplotlib. I'd be happy to collaborate on this effort if wanted/needed!
@TomNicholas
The text was updated successfully, but these errors were encountered: