Title: Added conversion from datetime to float for position and width parameters in violin plots by hasanrashid · Pull Request #30508 · matplotlib/matplotlib · GitHub
Open Graph Title: Added conversion from datetime to float for position and width parameters in violin plots by hasanrashid · Pull Request #30508 · matplotlib/matplotlib
X Title: Added conversion from datetime to float for position and width parameters in violin plots by hasanrashid · Pull Request #30508 · matplotlib/matplotlib
Description: PR summary This PR intends to close [ENH]: Support using datetimes as positions argument to violin(...) #30417 It should be possible to set the position of a violin plot to be a datetime. Currently, an attempt to do this results in this error message: TypeError: unsupported operand type(s) for +: 'float' and 'datetime.datetime' The error stems from trying to perform operations between float and datetime if datetime was provided as position arguments. The proposed solution: Converts datetimes in the "position" argument of a violin plot to float representation using date2num function in matplotlib.dates. Converts any "width" argument in the form of time difference to days. The violinplot tests in test_axes.py were successful An example that tests both "width" and "positions": Example: import datetime import matplotlib.pyplot as plt fig, ax = plt.subplots() datetimes = [ datetime.datetime(2023, 2, 10), datetime.datetime(2023, 5, 18), datetime.datetime(2023, 6, 6) ] ax.violin( [ { 'coords': datetimes, 'vals': [0.1, 0.5, 0.2], 'mean': datetimes[1], 'median': datetimes[1], 'min': datetimes[0], 'max': datetimes[-1], 'quantiles': datetimes } ], positions=[datetime.datetime(2023, 1, 1)], widths=[datetime.timedelta(days=1)] ) PR checklist "closes #30417" is in the body of the PR description to link the related issue new and changed code is tested Plotting related features are demonstrated in an example New Features and API Changes are noted with a directive and release note Documentation complies with general and docstring guidelines
Open Graph Description: PR summary This PR intends to close [ENH]: Support using datetimes as positions argument to violin(...) #30417 It should be possible to set the position of a violin plot to be a datetime. Currently...
X Description: PR summary This PR intends to close [ENH]: Support using datetimes as positions argument to violin(...) #30417 It should be possible to set the position of a violin plot to be a datetime. Currently...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/30508
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:889c50b3-f5ba-bc04-3e4c-d4af30d72324 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C122:3F42A4:8AD95F:BAE496:6A556119 |
| html-safe-nonce | f5c61b0f279ed2477e4a4b18a9d72ff0fe4c1b7b620c1d7d3485de2268cde199 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTIyOjNGNDJBNDo4QUQ5NUY6QkFFNDk2OjZBNTU2MTE5IiwidmlzaXRvcl9pZCI6IjQyMTI1ODQxNzI4Njk3Mzg3NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a091b53c2576e2038ef38ec4cc4580b32935d32edde864d9946fd7c72bfdec1f |
| hovercard-subject-tag | pull_request:2794270330 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/30508/files |
| twitter:image | https://avatars.githubusercontent.com/u/3212351?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3212351?s=400&v=4 |
| og:image:alt | PR summary This PR intends to close [ENH]: Support using datetimes as positions argument to violin(...) #30417 It should be possible to set the position of a violin plot to be a datetime. Currently... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8201d0b7bc32164c4662de52242e463a356df543 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width