Skip to content

[ENH]: align_titles #22376

Closed
Closed

Description

@anntzer

Problem

There's align_xlabels and align_ylabels to align the x and y labels, but no align_titles; this would be useful e.g. for

from pylab import *
fig, axs = subplots(1, 2, subplot_kw={"xlabel": "x", "ylabel": "y", "title": "t"})
axs[0].imshow(zeros((3, 5)))
axs[1].imshow(zeros((5, 3)))
fig.align_labels()

test

Proposed solution

Add Figure.align_titles.

Activity

  1. added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!
    on Feb 3, 2022
  2. QuLogic commented on Feb 3, 2022

    @QuLogic
    Member

    This is probably a good first issue; you have to copy what align_xlabels does, but using the title texts.

  3. pradhanvickey commented on Feb 9, 2022

    @pradhanvickey

    @QuLogic / @anntzer - I would like to work on this, can I give it a try? :)

  4. anntzer commented on Feb 9, 2022

    @anntzer
    ContributorAuthor

    Go for it.

  5. pradhanvickey commented on Feb 9, 2022

    @pradhanvickey

    Thanks @anntzer . Will start working on it

  6. weiji-li commented on Mar 21, 2022

    @weiji-li
    Contributor

    @pradhanvickey are you still working on this issue?

  7. jklymak commented on Mar 22, 2022

    @jklymak
    Member

    We tend not to reserve issues. If there is no PR feel free to submit one.

  8. neil-gurnani commented on Mar 23, 2022

    @neil-gurnani

    @QuLogic / @anntzer. Both @lijake8 and myself would like to work on this. Is this okay?

    Take

  9. kkoutris commented on Mar 28, 2022

    @kkoutris

    Is this issue still open?
    If yes can you assign me @anntzer ?

  10. kkoutris commented on Mar 28, 2022

    @kkoutris

    I don’t see any PR on the issue but probably @neil-gurnani is still working on it. I’ll wait a couple of days or look for a different issue.

  11. aswarner commented on Mar 30, 2022

    @aswarner

    I've been looking at this for a couple weeks -- it doesn't appear to be as easy as expected. We can replicate the grouping of axes with the the same rowspans, as done in align_xlabels(), however, updating the title location is done in the _AxesBase class, while the label updates are done in the Figure class. Importantly, the Figure class has access to subplots, but the axesBase class does not have a way to access the subplots or a grouper we make in the figure class, where align_titles() would exist. @anntzer I'm new to Matplotlib, was wondering if there is some workaround I'm missing to share the relevant data between the classes.

    Basically, we'd need to share either a grouper object or subplot location information from the Figure class (where the align_titles function would be written) to the axesBase class (where the title update occurs). Do you have any thoughts or are we missing anthing?

  12. jklymak commented on Mar 30, 2022

    @jklymak
    Member

    the title moving logic was copied from the x/ylabel moving logic, so aligning the titles should be possible after the automated moving that happens in Axes, just as its possible to align the x/y labels.

  13. jklymak commented on Mar 30, 2022

    @jklymak
    Member

    I took a quick look at this again. The logic in axis.py is exactly the same logic you would need to use in _base.py in _update_title_position. You can just make another _align_label_groups['titles']. I think there are some details to work out, but the information flow is exactly the same as for the way it is set up now.

  14. aswarner commented on Mar 30, 2022

    @aswarner

    Thank you for the response! That's what I tried, but I don't see how the AxesBase class in_base.pyhas access to the _align_label_groups['titles'] which is part of the FigureBase class.

  15. jklymak commented on Mar 30, 2022

    @jklymak
    Member

    Each axes has a self.figure.

  16. aswarner commented on Apr 3, 2022

    @aswarner

    @jklymak That helped! We figured it out and are working on testing and documentation

  17. christuangsit commented on Apr 2, 2024

    @christuangsit

    Hello, is this issue solved? If not, my friend and I would like to work on it.

  18. timhoffm commented on Apr 2, 2024

    @timhoffm
    Member

    The issue is open, so not solved yet. But as linked above, it has an associated open pull request, i.e. a solution proposal. Therefore it does not make sense to work on this issue. Please look for another topic if you want to contribute.

    As a side question, we often see people who ask in the way you did above coming from a CS course? Is that true for you as well? If so, which course and did they give you instructions on how to find suitable issues, in particular identifying whether an issue has already an associated open pull request and to judge whether that pull request is still active?

  19. added this to the v3.9.0 milestone on Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    New feature🌱 Good first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions