Skip to content
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

[ENH]: align_titles #22376

Closed
anntzer opened this issue Feb 2, 2022 · 18 comments · Fixed by #27952
Closed

[ENH]: align_titles #22376

anntzer opened this issue Feb 2, 2022 · 18 comments · Fixed by #27952
Labels
Good first issue Open a pull request against these issues if there are no active ones! New feature
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Feb 2, 2022

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.

@QuLogic QuLogic added the Good first issue Open a pull request against these issues if there are no active ones! label Feb 3, 2022
@QuLogic
Copy link
Member

QuLogic commented Feb 3, 2022

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

@pradhanvickey
Copy link

pradhanvickey commented Feb 9, 2022

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

@anntzer
Copy link
Contributor Author

anntzer commented Feb 9, 2022

Go for it.

@pradhanvickey
Copy link

Thanks @anntzer . Will start working on it

@weiji-li
Copy link
Contributor

@pradhanvickey are you still working on this issue?

@jklymak
Copy link
Member

jklymak commented Mar 22, 2022

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

@neil-gurnani
Copy link

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

Take

@kkoutris
Copy link

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

@anntzer
Copy link
Contributor Author

anntzer commented Mar 28, 2022

@kkoutris
Copy link

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.

@aswarner
Copy link

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?

@jklymak
Copy link
Member

jklymak commented Mar 30, 2022

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.

@jklymak
Copy link
Member

jklymak commented Mar 30, 2022

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.

@aswarner
Copy link

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.

@jklymak
Copy link
Member

jklymak commented Mar 30, 2022

Each axes has a self.figure.

@aswarner
Copy link

aswarner commented Apr 3, 2022

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

@christuangsit
Copy link

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

@timhoffm
Copy link
Member

timhoffm commented Apr 2, 2024

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?

@QuLogic QuLogic added this to the v3.9.0 milestone Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Open a pull request against these issues if there are no active ones! New feature
Projects
None yet
10 participants