FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Clarify that constrained_layout and tight_layout conflict with each other · Issue #17339 · matplotlib/matplotlib · GitHub

Repository navigation

Clarify that constrained_layout and tight_layout conflict with each other #17339

Closed

Description

Bug report

Bug summary

Not sure if this an expected behaviour, but the colorbar seems to be ignored when using tight_layout. Example taken from the "Constrained Layout Guide" (https://matplotlib.org/3.1.3/tutorials/intermediate/constrainedlayout_guide.html#colorbars).

Code for reproduction

arr = np.arange(100).reshape((10, 10))
fig, axs = plt.subplots(2, 2, figsize=(4, 4), constrained_layout=True)
for ax in axs.flat:
    im = ax.pcolormesh(arr)
fig.colorbar(im, ax=axs, shrink=0.6)
plt.tight_layout()

Actual outcome

Expected outcome
This is the outcome before calling plt.tight_layout()

Matplotlib version

  • Operating system: Fedora 31
  • Matplotlib version: 3.1.3 from conda defaults (3.2.1 from conda-forge behave similarly)
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.6
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. jklymak commented on May 6, 2020

    Member

    Yes, thats expected, or at least understood. You can use constrained_layout instead...

    Edit: tight_layout and constrained_layout are not compatible.

  2. QuLogic commented on May 6, 2020

    Member

    Maybe we should raise if calling tight_layout when the figure has constrained_layout enabled?

  3. jklymak commented on May 6, 2020

    Member

    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).

  4. QuLogic commented on May 7, 2020

    Member

    In the code above constrained_layout=True is ignored because tight_layout gets precedence (simply because its older).

    Does that generate a warning then?

  5. ericpre commented on May 7, 2020

    MemberAuthor

    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?

  6. jklymak commented on May 7, 2020

    Member

    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.

  7. changed the title [-]Colorbar ignored when calling tight_layout[/-] [+]Clarify that constrained_layout and tight_layout conflict with each other[/+] on May 7, 2020
  8. tacaswell commented on May 7, 2020

    Member

    At least on master we do warn:

    /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:

    1. add a sentance to the top indicating that constrained layout and tight layout are alternatives
    2. add a sub-section to https://matplotlib.org/tutorials/intermediate/constrainedlayout_guide.html#limitations showing tight_layout breaking this example.
  9. added this to the v3.4.0 milestone on May 7, 2020
  10. ericpre commented on May 7, 2020

    MemberAuthor

    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?

  11. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  12. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  13. 5 remaining items

  14. added this to the v3.6.3 milestone on Oct 27, 2022
  15. modified the milestones: v3.6.3, v3.7.0 on Jan 11, 2023
  16. modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  17. modified the milestones: v3.7.1, v3.7-doc on Mar 4, 2023
  18. modified the milestones: v3.7-doc, v3.8-doc on Sep 9, 2023
  19. added a commit that references this issue on Feb 6, 2025
    3e5788a
  20. added a commit that references this issue on Feb 28, 2025
    293eff8
  21. modified the milestones: v3.8-doc, v3.10.2 on Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL