René's URL Explorer Experiment


Title: [ENH]: Better positioning of rotated tick labels · Issue #28951 · matplotlib/matplotlib · GitHub

Open Graph Title: [ENH]: Better positioning of rotated tick labels · Issue #28951 · matplotlib/matplotlib

X Title: [ENH]: Better positioning of rotated tick labels · Issue #28951 · matplotlib/matplotlib

Description: Problem Tick labels are currently centered, also with rotation: plt.bar(range(3), [1, 3, 2], tick_label=['very long tick labels'] * 3) plt.tick_params(rotation=30) The rotated labels do not "point" to the ticks anymore, which can make it...

Open Graph Description: Problem Tick labels are currently centered, also with rotation: plt.bar(range(3), [1, 3, 2], tick_label=['very long tick labels'] * 3) plt.tick_params(rotation=30) The rotated labels do not "point"...

X Description: Problem Tick labels are currently centered, also with rotation: plt.bar(range(3), [1, 3, 2], tick_label=['very long tick labels'] * 3) plt.tick_params(rotation=30) The rotated labels do not...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28951

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Better positioning of rotated tick labels","articleBody":"### Problem\r\n\r\nTick labels are currently centered, also with rotation:\r\n\r\n```\r\nplt.bar(range(3), [1, 3, 2], tick_label=['very long tick labels'] * 3)\r\nplt.tick_params(rotation=30)\r\n```\r\n![image](https://github.com/user-attachments/assets/db074538-5fb6-477f-b130-a5fdbb7dda26)\r\n\r\nThe rotated labels do not \"point\" to the ticks anymore, which can make it difficult to see which label belongs to which tick - up to being outright misleading, e.g.\r\n\r\n```\r\nN = 20\r\nplt.bar(range(N), range(N), tick_label=[f'tick label {i}' for i in range(N)])\r\nplt.tick_params(rotation=45)\r\n```\r\n![image](https://github.com/user-attachments/assets/8932be5c-c65e-4cd3-ba66-290aa2ab1306)\r\n\r\nA common workaround is to adapt the alignment of the tick labels (e.g. demonstated in [this example](https://matplotlib.org/devdocs/gallery/ticks/date_concise_formatter.html#sphx-glr-gallery-ticks-date-concise-formatter-py)). The solution is not satisfying for two reasons:\r\n\r\n- The canonical way to adjust tick styles is `tick_params`, but we don't have alignment in there yet (and that has reasons, see https://github.com/matplotlib/matplotlib/issues/13774). Therefore people have to resort to setting the alignment on the individual tick instances, which has the major disadvantage that it does not work for dynamically changing plots because tick instances are volatile.\r\n- When rotating ticks, I expect that it \"just works\" and I don't have to additionally fine tune the result.\r\n\r\n### Proposed solution\r\n\r\nA new rotation algorithm that rotates the ticks appropriately. We can include this as a new `rotation_mode` type (see [Text.set_rotation_mode](https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text.set_rotation_mode)).\r\n\r\nEssentially, the labels should \"point\" towards their ticks. Note that this results in a very particular alignment: -90°, 0° and 90° want a centered alignment, whereas diagonal tick labels want a left/right alignment.\r\n\r\nOne can get approximately good results by tuning the alignment depending on the angle.\r\n\r\n\u003cdetails\u003e\r\n\u003csummary\u003eExample code (color coding for alignment: black: 'center', green: 'right', red: 'left')\u003c/summary\u003e\r\n\r\n```\r\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\n\r\ndef ha_for_angle(angle):\r\n    if angle \u003c -90 or angle \u003e 90:\r\n        raise ValueError('Todo: not thought about reasonable values for upside-down labels')\r\n    if angle \u003c -60:\r\n        return 'center'\r\n    if angle \u003c -5:\r\n        return 'left'\r\n    if angle \u003c= 5:\r\n        return 'center'\r\n    if angle \u003c= 60:\r\n        return 'right'\r\n    if angle \u003c= 90:\r\n        return 'center'\r\n   \r\n\r\nfig, ax = plt.subplots(figsize=(18, 1))\r\nangles = np.linspace(90, -90, 37)\r\nN = len(angles)\r\nax.set_xticks(range(N), ['label']*N)\r\nax.set_xlim(-0.5, N -0.5)\r\ntls = ax.xaxis.get_majorticklabels()\r\nfor ticklabel, angle in zip(tls, angles):\r\n    ha = ha_for_angle(angle)\r\n    color = {'left': 'r', 'center': 'k', 'right': 'g'}[ha]\r\n    ticklabel.set(rotation=angle, ha=ha, color=color)\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\n![image](https://github.com/user-attachments/assets/34d043b8-3e03-4758-b4eb-fc9bb334d122)\r\n\r\n\r\nWhile one could try and come up with mathematical more accurate text position methods, this simple trick gives reasonably good results.\r\n\r\n**Concrete suggestion:** Introduce rotation modes \"xtick\", \"ytick\" (exact names t.b.d.). \"xtick\" ignores the horizontal alignment setting and instead chooses a suitable one depending on the angle as above. Likewise \"ytick\" chooses a suitable vertical alignment.\r\n\r\nDepending on how strong we feel about backward compatibility, we can either make these rotation modes the default for ticks. Or we are defensive and only add it to `tick_params` for now, so that one could write `ax.xaxis.tick_params(rotation=45, rotation_mode='xtick')`.","author":{"url":"https://github.com/timhoffm","@type":"Person","name":"timhoffm"},"datePublished":"2024-10-07T20:38:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/28951/matplotlib/issues/28951"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:9efdd54c-8c88-0bed-8bc4-9343dde2ecfd
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id84D6:1FCD98:1FE6F9B:2A4C616:6A51EB31
html-safe-noncea4ca55e85f10d4b5654bcffa4b3c31bd588c94ce35c99355e1b6a9a3da2add9d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEQ2OjFGQ0Q5ODoxRkU2RjlCOjJBNEM2MTY6NkE1MUVCMzEiLCJ2aXNpdG9yX2lkIjoiNzAxNzY4NDA5MjIyODY3NzYxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacd0405db0e6a2137018cebe1582c5b4309f8f72c24a16dda0db8a7ad1e9237484
hovercard-subject-tagissue:2571426096
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/28951/issue_layout
twitter:imagehttps://opengraph.githubassets.com/896b454008bb9c97d119cfaaf55f063d5effe3f76e249c93f77e8501bc662532/matplotlib/matplotlib/issues/28951
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/896b454008bb9c97d119cfaaf55f063d5effe3f76e249c93f77e8501bc662532/matplotlib/matplotlib/issues/28951
og:image:altProblem Tick labels are currently centered, also with rotation: plt.bar(range(3), [1, 3, 2], tick_label=['very long tick labels'] * 3) plt.tick_params(rotation=30) The rotated labels do not "point"...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametimhoffm
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/28951#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F28951
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F28951
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/28951
Reloadhttps://github.com/matplotlib/matplotlib/issues/28951
Reloadhttps://github.com/matplotlib/matplotlib/issues/28951
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/28951
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/28951
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#28968https://github.com/matplotlib/matplotlib/pull/28968
[ENH]: Better positioning of rotated tick labelshttps://github.com/matplotlib/matplotlib/issues/28951#top
#28968https://github.com/matplotlib/matplotlib/pull/28968
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
v3.11.0https://github.com/matplotlib/matplotlib/milestone/96
https://github.com/timhoffm
timhoffmhttps://github.com/timhoffm
on Oct 7, 2024https://github.com/matplotlib/matplotlib/issues/28951#issue-2571426096
https://private-user-images.githubusercontent.com/2836374/374312783-db074538-5fb6-477f-b130-a5fdbb7dda26.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODM3NTM4MjEsIm5iZiI6MTc4Mzc1MzUyMSwicGF0aCI6Ii8yODM2Mzc0LzM3NDMxMjc4My1kYjA3NDUzOC01ZmI2LTQ3N2YtYjEzMC1hNWZkYmI3ZGRhMjYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MTFUMDcwNTIxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzBhODlhZTMzNjEwYTE1NjkwMmRjODU0YzdkZDI5NDQzZGM4MDNkZmYyNzY0ODA5NDQ3ZDllZTc4Yzg3NzgwMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.zGTUIMmlnjH5GGkQ0ogXDvzvzv3kggJlT02geWSa958
https://private-user-images.githubusercontent.com/2836374/374314440-8932be5c-c65e-4cd3-ba66-290aa2ab1306.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODM3NTM4MjEsIm5iZiI6MTc4Mzc1MzUyMSwicGF0aCI6Ii8yODM2Mzc0LzM3NDMxNDQ0MC04OTMyYmU1Yy1jNjVlLTRjZDMtYmE2Ni0yOTBhYTJhYjEzMDYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MTFUMDcwNTIxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmQ3Yzk5OGM3OTIwY2I3Y2YyYmVjOTVjYmI0ZWUxM2Q1ZDc3OWZlNzJlMzdmNjIwNDA2ZTQ5OTI0NTA0YmQxMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.lik37Ock-85lGBBHl5Hi79RYU3-LVSnBnD1rxoTkxU4
this examplehttps://matplotlib.org/devdocs/gallery/ticks/date_concise_formatter.html#sphx-glr-gallery-ticks-date-concise-formatter-py
No support for horizontal alignment in tick_params?  #13774https://github.com/matplotlib/matplotlib/issues/13774
Text.set_rotation_modehttps://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text.set_rotation_mode
https://private-user-images.githubusercontent.com/2836374/374320829-34d043b8-3e03-4758-b4eb-fc9bb334d122.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODM3NTM4MjEsIm5iZiI6MTc4Mzc1MzUyMSwicGF0aCI6Ii8yODM2Mzc0LzM3NDMyMDgyOS0zNGQwNDNiOC0zZTAzLTQ3NTgtYjRlYi1mYzliYjMzNGQxMjIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MDcxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjA3MTFUMDcwNTIxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzgyMGI4ZWE1NTEwYmE3MWNkNjIwMmI1NzFhYzEwZjQ0MWEyZjIzZjFmYTUwNmQzZWFiZDdkMjZmMjFjNGY0OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.lOe-nZvon0_gcAzaJylj0KQeKmbbmTpov5YQdf7pDas
New featurehttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22New%20feature%22
v3.11.0https://github.com/matplotlib/matplotlib/milestone/96
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.