-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
[Bug]: Adding suptitle in compressed layout causes weird spacing #27866
Comments
How can I make pull request for this issue by making new file in this repo or by editing in any other folder???? |
It seems like your fix involves adding the following code: plt.subplots_adjust(top=0.9) However, this seems to produce the following error:
This seems to indicate that this particular line of code isn't doing anything. And really, I don't see any difference in the figure. |
I would not say that this is a bug: It could be a feature request to have compressed layout move |
Ah, I see, so the inline layout is removing the space from the bottom. So, in reality, the two plots are vertically centered, it's just not showing up in jupyter lab. Am I getting this right? What I really want to achieve is have the plots stack from the top-down. And I know what aspect ratio I want the subplots to have. I don't really care how tall the final plot is, I just want to be able to set its width, and then have the height expand as needed. From my understanding, matplotlib doesn't really support this easily? Do you have any idea how I might go about doing this? |
@pavlin-policar you will definitely have to work around this issue. But how depends on why are you choosing to use suptitle in this situation versus a title on the top axes. |
Yes, that’s right. |
Yes, you are right.
A cheap workaround would be to use If you really want a suptitle, you'll have to tune the vertical position:
|
Thank you all for the wonderful suggestions! In my actual use case, I have a 2 by 2 grid of subplots, so setting the axis title for the the top-left axis wouldn't work, since the title wouldn't be centered on the overall plot. I only posted a minimal example to reproduce my problem. @timhoffm The second solution worked well for me. When saving to a file, it's important then to add Judging by all your (very helpful) comments, I suppose this isn't really a bug, but expected behavior, so I'll close the issue. The solution does feel a bit hacky though and I do wish there was like a |
I think this could stay open if someone wanted to fix it. I think it would just take a bit of logic in compressed layout to check for suptitle |
Bug summary
If I create a "compressed" layout with two rows with both subplots having fixed aspect ratios, adding a suptitle will insert the space between the suptitle and the plots. I would expect the excess space to be put in below the subplots.
Code for reproduction
Actual outcome
With suptitle:
Without suptitle:
Notably, this also happens without defining the gridspec kwargs.
Expected outcome
I would expect the extra spacing to be added at the bottom, not be inserted between the suptitle and the plots.
Additional information
No response
Operating system
OSX
Matplotlib Version
3.8.0
Matplotlib Backend
module://matplotlib_inline.backend_inline
I am running this inside jupyter lab, but this persists even if I save the figure to a file.
Python version
No response
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: