-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: constrained layout clips y-label above y-axis #27877
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
Comments
This was a conscious decision to avoid the case of a really long vertical ylabel driving the layout to make a tiny axes. For this situation I don't see the reason to use ylabel instead of text since you are doing all the placement manually anyway? |
That makes sense for a usual y-axis label. I think the second example (with a single line title) is not out of the ordinary and imho it should work as with tight layout. I want to provide a utility to match an existing template made for excel. I want to be as close to plain mpl as possible. So one would do I would rather not replace it with a Text or a hijack the title as it would break Anyway, can I tell |
I'm a little leery of too many toggles, but adding one is not out of the question. However, excelify could just as easily take whatever text is in the ylabel and make a new text object. Or as you suggest, add a dummy text object to force space for your ylabel. The user need no know this is happening. |
I mean, if a low-level placement parameter, like y, was used to set the y
label placement, then constrained layout should let the user shoot
themselves in the foot and disable the mechanism you described in your
first reply (probably guided by an internal variable). No need for a user
facing option.
For the specific problem I would rather not use a hack. I especially
don't want to break ax.yaxis.label.
9 Mar 2024 02.19.41 Jody Klymak ***@***.***>:
…
I'm a little leery of too many toggles, but adding one is not out of
the question.
However, excelify could just as easily take whatever text is in the
ylabel and make a new text object. Or as you suggest, add a dummy text
object to force space for your ylabel. The user need no know this is
happening.
—
Reply to this email directly, view it on
GitHub[#27877 (comment)],
or
unsubscribe[https://github.com/notifications/unsubscribe-auth/AAFCZXLWM75BEIYUQF7IQ43YXJPSNAVCNFSM6AAAAABELAQJOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWGY3TIMRWGE].
You are receiving this because you authored the thread.
[Tracking
image][https://github.com/notifications/beacon/AAFCZXLJJDKQDYFJAED72TDYXJPSNA5CNFSM6AAAAABELAQJOSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTWNI7FK.gif]
|
Finally dug into this. This was a purposeful change that affected both I'm not sure checking of the user manually specified y is a very good heuristic for toggling off this behaviour. Someone could have a tweaked y to be 0.2 or 0.7 for whatever reason and would want to keep the behaviour as-is So things are working as expected, and this is not a bug per-se. A toggle could likely be added if someone were motivated and the API could be clean enough. |
Thanks for the the reference and fair enough.
|
Bug summary
When placing the y-label above the y-axis/spine, it gets clipped with constrained layout. It works OK with tight layout and on the left in constrained layout.
Code for reproduction
Actual outcome
The y-label gets clipped. The second plot should have a two line long y label.

It also happens with a y-label that is just one line:

Expected outcome
I would expect the y label to be included, even when putting it above the axis. Example with tight layout (
fig1.tight_layout()
)Additional information
I think this is a bug(?).
I have tried various vertical alignments, and it doesn't make much of a difference. I also tried to follow the legend
set_in_layout
-example in the constrained layout guide without much luck.A temporary fix is to set the title to
' '
or increasing the constrained layout padding, I guess.Note that constrained layout works as expected with long y-labels on the left:
Operating system
Windows
Matplotlib Version
3.8.0
Matplotlib Backend
module://matplotlib_inline.backend_inline, but present in saved figures (
savefig
)Python version
3.12.1
Jupyter version
Jupyter console 6.6.3
Installation
conda
The text was updated successfully, but these errors were encountered: