-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
hooks to "prepare" xarray objects for plotting #5562
Comments
We discussed |
that will work if we want to remove the units, but |
wouldn't |
Oh I see. |
We would also want this to write pint-backed xarray datasets to netCDF. |
that makes sense, but I think long term it might be better to find a way to delegate this to duck array extension libraries (it really should call |
From xarray-contrib/pint-xarray#61 (comment)
matplotlib
has a module calledmatplotlib.units
which manages a mapping of types to hooks. This is then used to convert custom types to somethingmatplotlib
can work with, and to optionally add axis labels. For example, withpint
:this will plot the data without
UnitStrippedWarning
s and even attach the units as labels to the axis (the format is hard-coded inpint
right now).While this is pretty neat there are some issues:
xarray
's plotting code converts tomasked_array
, dropping metadata on the duck array (which meansmatplotlib
won't see the duck arrays)matplotlib
specific, which means we have to reimplement once we go through with the plotting entrypoints discussed in ENH: Plotting backend options #3553 and Add entrypoint for plotting backends #3640All of this makes me wonder: should we try to maintain our own mapping of hooks which "prepare" the object based on the data's type? My initial idea would be that the hook function receives a
Dataset
orDataArray
object and modifies it to convert the data tonumpy
arrays and optionally modifies theattrs
.For example for
pint
the hook would return the result of.pint.dequantify()
but it could also be used to explicitly call.get
oncupy
arrays or.todense
onsparse
arrays.xref #5561
The text was updated successfully, but these errors were encountered: