Thats not particularly the problem here; constrained_layout is a bit of a red herring. tight_layout just doesn't know about the big colorbar so ignores it. In the code above constrained_layout=True is ignored because tight_layout gets precedence (simply because its older).
If tight_layout and constrained_layout are not compatible, it would useful to have it documented - I can do this at some point.
Regardless of using constrained_layout or not, can you confirm the following: if I understand correctly, the colorbar is ignored by tight_layout because it is an instances of matplotlib.axes._axes.Axes and not matplotlib.axes._subplots.AxesSubplot?
Its says constrained_layout is to be used instead of tight_layout in quite a few places. They are not incompatible per se, just tight_layout cancels out constrained_layout.
changed the title [-]Colorbar ignored when calling tight_layout[/-][+]Clarify that constrained_layout and tight_layout conflict with each other[/+]on May 7, 2020
/tmp/pyIDWTj1:8: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
/tmp/pyIDWTj1:8: UserWarning: This figure was using constrained_layout==True, but that is incompatible with subplots_adjust and or tight_layout: setting constrained_layout==False.
This limitation of tight_layout was one of the motivations for writing constrained layout. I think action items here are:
add a sentance to the top indicating that constrained layout and tight layout are alternatives
Thanks for the explanations!
In the documentation, it is mentioned that both are alternatives but it is not clear, which one would be more useful. Even if there are many examples, it is not straightforward to work out which one would be more appropriate/robust. Maybe also add some simple guidelines or rule of thumb to the documentation?
Activity
jklymak commented on May 6, 2020
Yes, thats expected, or at least understood. You can use constrained_layout instead...
Edit: tight_layout and constrained_layout are not compatible.
QuLogic commented on May 6, 2020
Maybe we should raise if calling tight_layout when the figure has constrained_layout enabled?
jklymak commented on May 6, 2020
Thats not particularly the problem here; constrained_layout is a bit of a red herring. tight_layout just doesn't know about the big colorbar so ignores it. In the code above constrained_layout=True is ignored because tight_layout gets precedence (simply because its older).
QuLogic commented on May 7, 2020
Does that generate a warning then?
ericpre commented on May 7, 2020
If tight_layout and constrained_layout are not compatible, it would useful to have it documented - I can do this at some point.
Regardless of using constrained_layout or not, can you confirm the following: if I understand correctly, the colorbar is ignored by tight_layout because it is an instances of matplotlib.axes._axes.Axes and not matplotlib.axes._subplots.AxesSubplot?
jklymak commented on May 7, 2020
Its says constrained_layout is to be used instead of tight_layout in quite a few places. They are not incompatible per se, just tight_layout cancels out constrained_layout.
We could raise a warning I suppose.
tacaswell commented on May 7, 2020
At least on master we do warn:
This limitation of tight_layout was one of the motivations for writing constrained layout. I think action items here are:
ericpre commented on May 7, 2020
Thanks for the explanations!
In the documentation, it is mentioned that both are alternatives but it is not clear, which one would be more useful. Even if there are many examples, it is not straightforward to work out which one would be more appropriate/robust. Maybe also add some simple guidelines or rule of thumb to the documentation?
5 remaining items
DOC: Recommend constrained_layout over tight_layout
DOC: Recommend constrained_layout over tight_layout (#29584)