Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
ENH: Align titles#27952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
ENH: Align titles#27952
Changes fromall commits
Commits
Show all changes
5 commits Select commitHold shift + click to select a range
ecf1553 Implement align_titles based on align_xlabels
trananso2ff72be Add documentation for align_titles
trananso1dee172 Add unit test for align_titles
tranansoc947700 Switch gallery layout from tight to constrained
trananso0be9cca Increase error tolerance on image test to 0.022
tranansoFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletionsdoc/api/figure_api.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletionsdoc/users/next_whats_new/figure_align_titles.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| subplot titles can now be automatically aligned | ||
| ----------------------------------------------- | ||
| Subplot axes titles can be misaligned vertically if tick labels or | ||
| xlabels are placed at the top of one subplot. The new method on the | ||
| `.Figure` class: `.Figure.align_titles` will now align the titles | ||
| vertically. |
38 changes: 22 additions & 16 deletionsgalleries/examples/subplots_axes_and_figures/align_labels_demo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,43 @@ | ||
| """ | ||
| ========================== | ||
| Aligning Labels and Titles | ||
| ========================== | ||
| Aligning xlabel, ylabel,andtitle using `.Figure.align_xlabels`, | ||
| `.Figure.align_ylabels`, and `.Figure.align_titles`. | ||
| `.Figure.align_labels` wrapsthe x and y label functions. | ||
| Note that the xlabel "XLabel1 1" would normally be much closer to the | ||
| x-axis,"YLabel0 0" would be much closer to the y-axis, and title | ||
| "Title0 0" would be much closer to the top of theirrespective axes. | ||
| """ | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
| fig, axs = plt.subplots(2, 2, layout='constrained') | ||
| ax = axs[0][0] | ||
| ax.plot(np.arange(0, 1e6, 1000)) | ||
| ax.set_title('Title0 0') | ||
| ax.set_ylabel('YLabel0 0') | ||
| ax = axs[0][1] | ||
| ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1)) | ||
| ax.set_title('Title0 1') | ||
| ax.xaxis.tick_top() | ||
| ax.tick_params(axis='x', rotation=55) | ||
| for i in range(2): | ||
| ax =axs[1][i] | ||
| ax.plot(np.arange(1., 0., -0.1) * 2000., np.arange(1., 0., -0.1)) | ||
| ax.set_ylabel('YLabel1 %d' % i) | ||
| ax.set_xlabel('XLabel1 %d' % i) | ||
| if i == 0: | ||
| ax.tick_params(axis='x', rotation=55) | ||
| fig.align_labels() # same as fig.align_xlabels(); fig.align_ylabels() | ||
| fig.align_titles() | ||
| plt.show() |
9 changes: 7 additions & 2 deletionslib/matplotlib/axes/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
65 changes: 59 additions & 6 deletionslib/matplotlib/figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionslib/matplotlib/figure.pyi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong.Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletionslib/matplotlib/tests/test_figure.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.