Skip to content

[ENH]: add Figure.align_titles() functionality #22793

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from

Conversation

aswarner
Copy link

@aswarner aswarner commented Apr 6, 2022

PR Summary

Resolves #22376 . Add Figure.align_titles() function, which automatically aligns titles of subplots on a single figure, in the style of align_labels().

NOTE: This PR contains tested code but we still need to complete documentation and pytest.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@aswarner
Copy link
Author

aswarner commented Apr 6, 2022

We are working on documentation/testing and need to squash the commits.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@QuLogic QuLogic marked this pull request as draft April 7, 2022 03:28
@oscargus oscargus added topic: ticks axis labels topic: axes status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. and removed topic: axes labels Apr 7, 2022
@oscargus oscargus added this to the v3.6.0 milestone Apr 7, 2022
@@ -1241,6 +1242,60 @@ def align_xlabels(self, axs=None):
# grouper for groups of xlabels to align
self._align_label_groups['x'].join(ax, axc)

def align_titles(self, axs=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want to add align_titles to align_labels? Though this would be a breaking change of align_labels.

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good! Not set on rolling into _align_label_groups, but might be more compact.

@aswarner
Copy link
Author

We aligned the titles by changing the image bounding boxes, which works with plt.show() , but not with savefig or pytest (the image rendered for a pytest doesn't have aligned titles) due to the differing chain of function calls. Is this an infrastructure issue that has a workaround?

@jklymak
Copy link
Member

jklymak commented Apr 11, 2022

I am not on my computer for a few days to look properly what you mean. However the alignment should work the same as for x and y labels. All of them may need a draw before they are correct to get the text sizes correct.

update test

first

copy a bbox function to axesBase from figure

add broken code? commented out

align titles works

finish code and add tests

add demo

remove readme2
@@ -0,0 +1,26 @@
"""
===============
Aligning Labels
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Aligning Labels
Aligning Titles

?

@@ -2950,7 +2950,7 @@ def _update_title_position(self, renderer):
_log.debug('title position was updated manually, not adjusting')
return

titles = (self.title, self._left_title, self._right_title)
titles = [self.title, self._left_title, self._right_title]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? It doesn't look like you are actually modifying titles.

@oscargus oscargus removed the status: needs workflow approval For PRs from new contributors, from which GitHub blocks workflows by default. label Aug 19, 2022
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Aug 24, 2022
@@ -2950,7 +2950,7 @@ def _update_title_position(self, renderer):
_log.debug('title position was updated manually, not adjusting')
return

titles = (self.title, self._left_title, self._right_title)
titles = [self.title, self._left_title, self._right_title]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
titles = [self.title, self._left_title, self._right_title]
titles = (self.title, self._left_title, self._right_title)

@melissawm
Copy link
Member

Hi @aswarner - can we help you move this forward? Thanks!

@QuLogic QuLogic modified the milestones: v3.7.0, v3.8.0 Jan 4, 2023
@jklymak
Copy link
Member

jklymak commented Feb 9, 2023

ping @aswarner just had another request for this feature today. If you are not moving forward with the PR, should we open up to other folks? Thanks!

@AlextheGreat1509 AlextheGreat1509 mentioned this pull request Mar 31, 2023
2 tasks
@ksunden ksunden modified the milestones: v3.8.0, future releases Aug 8, 2023
trananso added a commit to trananso/matplotlib that referenced this pull request Mar 19, 2024
@trananso trananso mentioned this pull request Mar 20, 2024
5 tasks
trananso added a commit to trananso/matplotlib that referenced this pull request Mar 20, 2024
@rcomer
Copy link
Member

rcomer commented Mar 31, 2024

Closing in favour of #27952.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for author
Development

Successfully merging this pull request may close these issues.

[ENH]: align_titles
9 participants