Title: [ENH]: Better support for stackplot with units [particularly datetimes] · Issue #27129 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Better support for stackplot with units [particularly datetimes] · Issue #27129 · matplotlib/matplotlib
X Title: [ENH]: Better support for stackplot with units [particularly datetimes] · Issue #27129 · matplotlib/matplotlib
Description: Problem As noted during the review of #27114, the current support of units in stackplot is subpar, particularly for the y axis. For datetimes in particular, the implicit 0 of the API is problematic, introducing 1970-01-01 when that is no...
Open Graph Description: Problem As noted during the review of #27114, the current support of units in stackplot is subpar, particularly for the y axis. For datetimes in particular, the implicit 0 of the API is problematic...
X Description: Problem As noted during the review of #27114, the current support of units in stackplot is subpar, particularly for the y axis. For datetimes in particular, the implicit 0 of the API is problematic...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/27129
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Better support for stackplot with units [particularly datetimes]","articleBody":"### Problem\r\n\r\nAs noted during the review of #27114, the current support of units in stackplot is subpar, particularly for the `y` axis.\r\n\r\nFor datetimes in particular, the implicit 0 of the API is problematic, introducing 1970-01-01 when that is not a relevant date.\r\n\r\nTherefore I suggest allowing `baseline` to be not only the current supported string literals, but also a scalar value (or potentially an array, I guess) such that a \"sensible\" baseline can be provided for cases where `0` is not sensible. (even the other options for baseline assume you want your plot centered around 0... I'm not concerned about wanting \"wiggle centered at 2023-02-28\" or anything like that, that seems perhaps a bridge too far.)\r\n\r\nI also think it is important to explicitly state that the y values are in delta units (similar to how we do for e.g. [`bar`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.bar.html#matplotlib.axes.Axes.bar) for the `width` parameter. This is already true in that adding actual datetime values will fail, but passing timedelta objects will work.\r\n\r\nFinally, the `cumsum` call contains a `promote_types(y.dtype, np.float32)`, which will fail for `np.timedelta64` arrays (Edit, to be consistent with other points, clarified that I really meant timedelta instead of datetime64 here):\r\n\r\nhttps://github.com/matplotlib/matplotlib/blob/39582424f8ce5e042e4e39eeac94893f222c9f8b/lib/matplotlib/stackplot.py#L81\r\n\r\nSo either removing that or at least handling the error case is needed. It's not fully clear to me what we are guarding against there, as `cumsum` of integers is fine being integral, though I guess we _could_ run into overflow issues? Passing `datetime.timedelta` as `object` arrays (or as lists which get turned into `object` arrays) will work and produce _a_ plot, just without a sensible baseline, currently. \r\n\r\n### Proposed solution\r\n\r\n_No response_","author":{"url":"https://github.com/ksunden","@type":"Person","name":"ksunden"},"datePublished":"2023-10-17T22:44:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/27129/matplotlib/issues/27129"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:03b294f3-abaa-8a28-d214-89b6daaba7a5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C52C:B6D9A:E474EC:131EC42:6A5290D3 |
| html-safe-nonce | c842cec8fea1524aa5260e590940facd9ad9263a363e876f763ac4004536efc2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTJDOkI2RDlBOkU0NzRFQzoxMzFFQzQyOjZBNTI5MEQzIiwidmlzaXRvcl9pZCI6IjE0MDA3MzA4NTg2OTI5NzI3NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 35d39907aaae460c29af0cdf0e256e78c42d9d44c62a341a6c410b0318afa0df |
| hovercard-subject-tag | issue:1948412037 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/27129/issue_layout |
| twitter:image | https://opengraph.githubassets.com/da6d04684f1313836f4731c9bc7f0ff1ae4f7b30c4443068adcf281271ea2e4a/matplotlib/matplotlib/issues/27129 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/da6d04684f1313836f4731c9bc7f0ff1ae4f7b30c4443068adcf281271ea2e4a/matplotlib/matplotlib/issues/27129 |
| og:image:alt | Problem As noted during the review of #27114, the current support of units in stackplot is subpar, particularly for the y axis. For datetimes in particular, the implicit 0 of the API is problematic... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ksunden |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width