home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 935531700

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
935531700 MDU6SXNzdWU5MzU1MzE3MDA= 5562 hooks to "prepare" xarray objects for plotting 14808389 open 0     6 2021-07-02T08:14:02Z 2021-07-04T08:46:34Z   MEMBER      

From https://github.com/xarray-contrib/pint-xarray/pull/61#discussion_r662485351

matplotlib has a module called matplotlib.units which manages a mapping of types to hooks. This is then used to convert custom types to something matplotlib can work with, and to optionally add axis labels. For example, with pint: python In [9]: ureg = pint.UnitRegistry() ...: ureg.setup_matplotlib() ...: ...: t = ureg.Quantity(np.arange(10), "s") ...: v = ureg.Quantity(5, "m / s") ...: x = v * t ...: ...: fig, ax = plt.subplots(1, 1) ...: ax.plot(t, x) ...: ...: plt.show() this will plot the data without UnitStrippedWarnings and even attach the units as labels to the axis (the format is hard-coded in pint right now).

While this is pretty neat there are some issues: - xarray's plotting code converts to masked_array, dropping metadata on the duck array (which means matplotlib won't see the duck arrays) - we will end up overwriting the axis labels once the variable names are added (not sure if there's a way to specify a label format?) - it is matplotlib specific, which means we have to reimplement once we go through with the plotting entrypoints discussed in #3553 and #3640

All 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 or DataArray object and modifies it to convert the data to numpy arrays and optionally modifies the attrs.

For example for pint the hook would return the result of .pint.dequantify() but it could also be used to explicitly call .get on cupy arrays or .todense on sparse arrays.

xref #5561

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5562/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 6 rows from issue in issue_comments
Powered by Datasette · Queries took 402.756ms · About: xarray-datasette