Title: Make Axis.get_tick_space account for tick label rotation by m4nn2609-dot · Pull Request #32056 · matplotlib/matplotlib · GitHub
Open Graph Title: Make Axis.get_tick_space account for tick label rotation by m4nn2609-dot · Pull Request #32056 · matplotlib/matplotlib
X Title: Make Axis.get_tick_space account for tick label rotation by m4nn2609-dot · Pull Request #32056 · matplotlib/matplotlib
Description: PR summary closes #32005 Axis.get_tick_space() estimates the number of ticks that fit on an axis by dividing the available length by an estimated tick label size. That estimate assumes tick labels are drawn horizontally (a fixed aspect-ratio heuristic: 3:1 for the x-axis, 2:1 for the y-axis), so rotating labels via tick_params(rotation=...) produces poor tick spacing, as shown in the linked issue's reproduction. This PR makes the estimate aware of label rotation: Added Axis._get_tick_label_rotation(), which reads the rotation angle stored in _major_tick_kw['labelrotation'] (set via tick_params). XAxis.get_tick_space() and YAxis.get_tick_space() now blend the aspect-ratio heuristic between the horizontal and vertical cases using the rotation angle: aspect = |horizontal_factor * cos(theta)| + |vertical_factor * sin(theta)| At theta = 0 this is identical to the current behavior, so unrotated labels are unaffected. As rotation approaches 90 degrees, the x-axis estimate shrinks towards a single line-height, and the y-axis estimate grows towards the horizontal-text ratio. This keeps the estimate cheap (no actual text measurement is performed), consistent with the existing design intent noted in _get_tick_label_size's docstring, which avoids creating a Tick object for performance reasons. AI Disclosure I used an AI assistant (Claude) as a tutor while working on this: to help me understand how get_tick_space and the tick-rotation storage in _major_tick_kw work, to talk through possible approaches (including a simpler threshold-based alternative I considered and decided against), and to help troubleshoot my local dev environment setup. I wrote and reviewed the final diff myself and understand the reasoning behind it. PR checklist "closes #32005" is in the body of the PR description 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 closes #32005 Axis.get_tick_space() estimates the number of ticks that fit on an axis by dividing the available length by an estimated tick label size. That estimate assumes tick labels ...
X Description: PR summary closes #32005 Axis.get_tick_space() estimates the number of ticks that fit on an axis by dividing the available length by an estimated tick label size. That estimate assumes tick labels ...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/32056
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6d6b7010-2e7f-693f-c7dd-9d6d899143c1 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CA64:1E59EF:166B74:1FD42C:6A63641B |
| html-safe-nonce | 6afb02ccd1d05b32273cecc10912890be1d2cf7df38a01ecdf6d2ff5c429b030 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQTY0OjFFNTlFRjoxNjZCNzQ6MUZENDJDOjZBNjM2NDFCIiwidmlzaXRvcl9pZCI6IjcwMDcwNzUxNzk0MjE2MjQ1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | dd9600612817fffbcf4bb48795da3a76e331b99b295d0be2050ebf503ce5a669 |
| hovercard-subject-tag | pull_request:4077192821 |
| 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/32056/files |
| twitter:image | https://avatars.githubusercontent.com/u/294705807?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/294705807?s=400&v=4 |
| og:image:alt | PR summary closes #32005 Axis.get_tick_space() estimates the number of ticks that fit on an axis by dividing the available length by an estimated tick label size. That estimate assumes tick labels ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 669d3fcd704a169521d2b6431762f95a6878a9e8ccaf0fd5f2d0802fc5b971f9 |
| 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 | 20da292f132ff51328be50073854259f417052c1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width