Title: [ENH]: ticker.EngFormatter: allow offset · Issue #28463 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: ticker.EngFormatter: allow offset · Issue #28463 · matplotlib/matplotlib
X Title: [ENH]: ticker.EngFormatter: allow offset · Issue #28463 · matplotlib/matplotlib
Description: Problem I want to be able to generate this plot: I managed to create this plot using the following code: from itertools import count from math import copysign # https://pypi.org/project/prefixed/ from prefixed import Float from matplotli...
Open Graph Description: Problem I want to be able to generate this plot: I managed to create this plot using the following code: from itertools import count from math import copysign # https://pypi.org/project/prefixed/ f...
X Description: Problem I want to be able to generate this plot: I managed to create this plot using the following code: from itertools import count from math import copysign # https://pypi.org/project/prefixed/ f...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28463
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: ticker.EngFormatter: allow offset","articleBody":"### Problem\n\nI want to be able to generate this plot:\r\n\r\n\r\n\r\nI managed to create this plot using the following code:\r\n\r\n```python\r\nfrom itertools import count\r\nfrom math import copysign\r\n\r\n# https://pypi.org/project/prefixed/\r\nfrom prefixed import Float\r\n\r\nfrom matplotlib.ticker import ScalarFormatter\r\n\r\nclass FrequencyFormatter(ScalarFormatter):\r\n def format_data(self, value):\r\n # Add the Hz suffix\r\n return '{:H}Hz'.format(Float(value))\r\n def _set_order_of_magnitude(self):\r\n super()._set_order_of_magnitude()\r\n c = abs(self.orderOfMagnitude)\r\n # Search 0, -3, 3, -6, 6, -9, 9 etc until the best scientifically\r\n # prefixed oom is found, and then set self.orderOfMagnitude to it\r\n for sciOom in count(3,3):\r\n if c \u003c sciOom:\r\n self.orderOfMagnitude = copysign(sciOom, self.orderOfMagnitude)\r\n break\r\n\r\n# fig,ax...\r\n\r\nax.yaxis.set_major_formatter(FrequencyFormatter(\r\n # I'm not necessarily interested in this, but without this,\r\n # ScalarFormatter.get_offset doesn't use my own .format_data function to\r\n # format also the offset.\r\n useMathText=True\r\n))\r\n```\r\n\r\nIt is not ideal because it relies both upon modifying (the private) `_set_order_of_magnitude` method and the external library `prefixed`, which implements something already implemented in the [`EngFormatter`](https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.EngFormatter).\r\n\r\nI'm surprised that [`EngFormatter`](https://matplotlib.org/stable/api/ticker_api.html#matplotlib.ticker.EngFormatter) doesn't handle offsets so smartly like `ScalarFormatter`...\r\n\r\nWhere do you think this kind of enhancement would fit most? In `EngFormatter` with an additional `__init__` argument? Or in a new formatter?\n\n### Proposed solution\n\nSort of proposed above...","author":{"url":"https://github.com/doronbehar","@type":"Person","name":"doronbehar"},"datePublished":"2024-06-25T23:10:34.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/28463/matplotlib/issues/28463"}
| 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:741a64e3-3d5d-db49-86e5-0695575b9c49 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C000:34F7A0:1195382:173A38A:6A542515 |
| html-safe-nonce | 40d838cfd772c1c72e2a218385b1aa14b7d8c736c58588e387fd053c7f92ecb9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDAwOjM0RjdBMDoxMTk1MzgyOjE3M0EzOEE6NkE1NDI1MTUiLCJ2aXNpdG9yX2lkIjoiNTY2MTM2NTE0ODIwMTUyNjU0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 90f7a9517f5de42f692b05fb4257e1bfc9baefe50602c0c8d42db1f613804625 |
| hovercard-subject-tag | issue:2373828679 |
| 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/28463/issue_layout |
| twitter:image | https://opengraph.githubassets.com/282f0b0e66a7ace952d45749af47309057de1f32019c5a7f1ec90062cd858182/matplotlib/matplotlib/issues/28463 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/282f0b0e66a7ace952d45749af47309057de1f32019c5a7f1ec90062cd858182/matplotlib/matplotlib/issues/28463 |
| og:image:alt | Problem I want to be able to generate this plot: I managed to create this plot using the following code: from itertools import count from math import copysign # https://pypi.org/project/prefixed/ f... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | doronbehar |
| 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