Title: [Bug]: `get_ticklabels`/`set_ticklabels` gives incorrect values in log plot · Issue #29284 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: `get_ticklabels`/`set_ticklabels` gives incorrect values in log plot · Issue #29284 · matplotlib/matplotlib
X Title: [Bug]: `get_ticklabels`/`set_ticklabels` gives incorrect values in log plot · Issue #29284 · matplotlib/matplotlib
Description: Bug summary In a certain scenario, adjusting the ylim of a log plot and updating the yticklabels gives numerically incorrect ticks while still plotting the correct values. We were calling get_/set_yticklabels because the cmss10 font didn...
Open Graph Description: Bug summary In a certain scenario, adjusting the ylim of a log plot and updating the yticklabels gives numerically incorrect ticks while still plotting the correct values. We were calling get_/set_...
X Description: Bug summary In a certain scenario, adjusting the ylim of a log plot and updating the yticklabels gives numerically incorrect ticks while still plotting the correct values. We were calling get_/set_...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/29284
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: `get_ticklabels`/`set_ticklabels` gives incorrect values in log plot","articleBody":"### Bug summary\n\nIn a certain scenario, adjusting the `ylim` of a log plot and updating the `yticklabels` gives numerically incorrect ticks while still plotting the correct values. We were calling `get_`/`set_yticklabels` because the `cmss10` font didn't have a certain glyph which needed to be replaced, but the bug can be reproduced with the more minimal code below.\n\n### Code for reproduction\n\n```Python\nimport matplotlib.pyplot as plt\r\n\r\nplt.rcParams.update({\r\n \"figure.figsize\": (6, 2),\r\n \"font.size\": 12,\r\n \"font.family\": \"cmss10\",\r\n})\r\n\r\nx = ['A', 'B', 'C']\r\ny = [10, 1000, 10000]\r\n\r\nfig, ax = plt.subplots(layout='constrained')\r\n\r\n# Plot and label data\r\nb = ax.bar(x, y)\r\nax.bar_label(b, y)\r\n\r\n# Log scale for vertical axis\r\nax.set_yscale('log')\r\n\r\n# Give a bit extra space for the labels\r\nplt.ylim(None, plt.ylim()[1] * 8)\r\n\r\n# Originally was using this to replace special characters in the font\r\nax.set_yticklabels(ax.get_yticklabels())\r\n\r\nplt.savefig('bug-output.png', dpi=300)\n```\n\n\n### Actual outcome\n\n\r\n\r\nThe y-axis ticks are incorrectly labeled.\n\n### Expected outcome\n\n\r\n\r\n\r\n\n\n### Additional information\n\nChanging `plt.ylim(None, plt.ylim()[1] * 8)` to `plt.ylim(None, plt.ylim()[1] * 7)` (that is, just a bit less extra room) fixes the issue. Granted, most other sets of changes also fix it: this appears to be an extremely idiosyncratic bug, so I'm not clear what the real issue is. Changing the plot size, removing `'constrained'`, changing the font, removing the `ylim` statement entirely... these all appear to fix it. It's just the specific combination of parameters that we happened to stumble into this.\n\n### Operating system\n\nMac OS\n\n### Matplotlib Version\n\n3.9.3\n\n### Matplotlib Backend\n\nmacosx\n\n### Python version\n\n3.10.2\n\n### Jupyter version\n\nN/A\n\n### Installation\n\npip","author":{"url":"https://github.com/elimbaum","@type":"Person","name":"elimbaum"},"datePublished":"2024-12-11T14:58:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/29284/matplotlib/issues/29284"}
| 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:e9120296-41f7-b4fa-fc6b-52f02d6244ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFE4:1A8743:2B2A8CC:3AD1C1F:6A548FE5 |
| html-safe-nonce | 85fa64a963531e32cdd62811f366a22d293ac9ac4e0593b833d0977b946d1031 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkU0OjFBODc0MzoyQjJBOENDOjNBRDFDMUY6NkE1NDhGRTUiLCJ2aXNpdG9yX2lkIjoiNDQ5NTM0ODAzNDkwNjEzMjQ1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4e7f60764209923c2cdc55ad605d6d35c9ba07cdc3700cdbd0e5bed43c17e211 |
| hovercard-subject-tag | issue:2733213223 |
| 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/29284/issue_layout |
| twitter:image | https://opengraph.githubassets.com/553c673a4cead6c72b2fbc95be2302763b173ee966d5e06cec5872d895b9058c/matplotlib/matplotlib/issues/29284 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/553c673a4cead6c72b2fbc95be2302763b173ee966d5e06cec5872d895b9058c/matplotlib/matplotlib/issues/29284 |
| og:image:alt | Bug summary In a certain scenario, adjusting the ylim of a log plot and updating the yticklabels gives numerically incorrect ticks while still plotting the correct values. We were calling get_/set_... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | elimbaum |
| 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 | f8cfff6384f62259baea531c7f58bc7040f8dd92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width