Title: Implement xtick and ytick rotation modes by kyracho · Pull Request #28968 · matplotlib/matplotlib · GitHub
Open Graph Title: Implement xtick and ytick rotation modes by kyracho · Pull Request #28968 · matplotlib/matplotlib
X Title: Implement xtick and ytick rotation modes by kyracho · Pull Request #28968 · matplotlib/matplotlib
Description: Hello, the goal of this PR is to implement two new rotation_mode types 'xtick' and 'ytick' for the axis labels. The idea is that these new rotation_modes automatically set the label alignments to match any rotation in $[0,360)$. 'xtick' aligns the x-axis labels, and 'ytick' aligns the y-axis labels. Closes #28951 Plots illustrating the proposed 'xtick' and 'ytick' rotation modes: For bottom and left labels: import matplotlib.pyplot as plt import numpy as np t = np.linspace(0, 2 * np.pi, 1000) r = np.cos(6 * t) x_flower = r * np.cos(t) y_flower = r * np.sin(t) angles, n_cols = np.linspace(0, 360, 25), 5 fig, axs = plt.subplots(nrows=5, ncols=n_cols, figsize=(30, 30)) axs = axs.flatten() labels = ['label' for i in range(8)] for i, angle in enumerate(angles): ax = axs[i] ax.set_title(f'Rotation: {angle:.0f}°', fontsize=10) ax.set_xticks(np.linspace(0, 1.3, 8).tolist()) ax.set_xticklabels(labels) # ax.xaxis.tick_top() ax.xaxis.set_tick_params(rotation = angle, rotation_mode='xtick') ax.set_yticks(np.linspace(0, 1.3, 8).tolist()) ax.set_yticklabels(labels) # ax.yaxis.tick_right() ax.yaxis.set_tick_params(rotation = angle, rotation_mode='ytick') ax.set_xlim(0, 1.3) ax.set_ylim(0, 1.3) ax.plot(x_flower * 0.5 + 0.65, y_flower * 0.5 + 0.65, color='purple') plt.tight_layout() plt.savefig('rotated_ticks_figure') plt.show() For top and right labels: import matplotlib.pyplot as plt import numpy as np t = np.linspace(0, 2 * np.pi, 1000) r = np.cos(6 * t) x_flower = r * np.cos(t) y_flower = r * np.sin(t) angles, n_cols = np.linspace(0, 360, 25), 5 fig, axs = plt.subplots(nrows=5, ncols=n_cols, figsize=(30, 30)) axs = axs.flatten() labels = ['label' for i in range(8)] for i, angle in enumerate(angles): ax = axs[i] ax.set_title(f'Rotation: {angle:.0f}°', fontsize=10) ax.set_xticks(np.linspace(0, 1.3, 8).tolist()) ax.set_xticklabels(labels) ax.xaxis.tick_top() ax.xaxis.set_tick_params(rotation = angle, rotation_mode='xtick') ax.set_yticks(np.linspace(0, 1.3, 8).tolist()) ax.set_yticklabels(labels) ax.yaxis.tick_right() ax.yaxis.set_tick_params(rotation = angle, rotation_mode='ytick') ax.set_xlim(0, 1.3) ax.set_ylim(0, 1.3) ax.plot(x_flower * 0.5 + 0.65, y_flower * 0.5 + 0.65, color='purple') plt.tight_layout() plt.savefig('rotated_ticks_figure') plt.show() PR checklist "closes #0000" 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: Hello, the goal of this PR is to implement two new rotation_mode types 'xtick' and 'ytick' for the axis labels. The idea is that these new rotation_modes automatically set the label...
X Description: Hello, the goal of this PR is to implement two new rotation_mode types 'xtick' and 'ytick' for the axis labels. The idea is that these new rotation_modes automatical...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/28968
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:29e6c6e1-e9bd-6635-f71a-1d66fe5781e3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BE42:71E1B:D96A0E:1221821:6A51B849 |
| html-safe-nonce | a82a4b641400486042a02eca87d3b66fa34db90c957eed53c425faea620706fb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTQyOjcxRTFCOkQ5NkEwRToxMjIxODIxOjZBNTFCODQ5IiwidmlzaXRvcl9pZCI6IjI3Nzc1ODQwNTg1NDIxNDIxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7d41e3529a8ce158ceeea8239ef2cbd4f2c92d27bd021def4622b412c2972717 |
| hovercard-subject-tag | pull_request:2119499031 |
| 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/28968/files |
| twitter:image | https://avatars.githubusercontent.com/u/170383634?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/170383634?s=400&v=4 |
| og:image:alt | Hello, the goal of this PR is to implement two new rotation_mode types 'xtick' and 'ytick' for the axis labels. The idea is that these new rotation_modes automatically set the label... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width