cf-xarray icon indicating copy to clipboard operation
cf-xarray copied to clipboard

add Dataset plot accessor.

Open dcherian opened this issue 4 years ago • 4 comments

to wrap _DatasetPlotMethods.

This should be easy → follow what is done with _CFPlotMethods

dcherian avatar Jun 18 '20 19:06 dcherian

@dcherian Where does _DatasetPlotMethods exist? I can't find it in this repository's code. And I only see one reference to _CFPlotMethods -- https://github.com/xarray-contrib/cf-xarray/blob/19d80cf48bf99e541f084f97c5ed84b83332d0bd/cf_xarray/accessor.py#L482

Are these upstream in Xarray?

jukent avatar Dec 16 '20 18:12 jukent

I may have changed design since this was written. I think now we just need to modify _CFPlotMethods appropriately to work.

We want the following to work:

import cf_xarray
import xarray as xr

ds = xr.tutorial.load_dataset("air_temperature").isel(time=slice(2))
ds.air.attrs["standard_name"] = "air_temperature"
ds.plot.scatter(x="air", y="lat")  # works
ds.cf.plot.scatter(x="air_temperature", y="latitude")  # doesn't work

https://github.com/xarray-contrib/cf-xarray/blob/19d80cf48bf99e541f084f97c5ed84b83332d0bd/cf_xarray/accessor.py#L624 We should add the _get_standard_name mapper to the above dictionary. I think that might be all that's needed to get scatter to work.

dcherian avatar Dec 16 '20 18:12 dcherian

_get_standard_name

I'm a little iffy on using the dict.fromkeys method with more than one value. Would it look something like:

key_mappers=dict.fromkeys(self._keys, (_get_axis_coord_single, _get_standard_name)), ?

jukent avatar Jan 14 '21 00:01 jukent

Yes

dcherian avatar Jan 14 '21 14:01 dcherian