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

Should constrained_layout be applied every draw? · Issue #11630 · matplotlib/matplotlib · GitHub

Repository navigation

Should constrained_layout be applied every draw? #11630

Closed

Description

Discussion

Right now fig, ax = plt.subplots(constrained_layout=True) will cause the axes resizing to be carried out every draw event; hence the axes get repositioned if the figure changes size, or if zoom is applied, or panning, etc.

Is this desirable?

plt.tight_layout() is only called once, and does not get activated at draw time.

Pros:

  • if the window is resized, the axes positions are recalculated. That means the padding and margins expand or contract as the window gets smaller or larger.
  • if we zoom, and the ticklabels get much longer (i.e. more decimal places), the axes get resized.

Cons:

  • under zoom the axes keep changing size. That can be distracting. It doesn't always work either because there is a strange interaction with zoom and clipping boxes for artists.
  • for a plot w/ lots of axes it makes zooming/panning less responsive.

Any opinions? For my usual workflow, I'm probably fine with just calling constrained layout on the original plot. Any zooming etc are done on working plots versus final presentation plots, and I hard code limits in after the exploration stage. But I get the feeling some people use a lot of GUI work before saving their plots.

Activity

  1. timhoffm commented on Jul 11, 2018

    Member

    It may be worth making the behavior configurable. As you said, there are use-cases for both scenarios.

  2. ImportanceOfBeingErnest commented on Jul 11, 2018

    Member

    I have a crazy idea: tight_layout can be called from within the GUI

    Would it make sense to add another button for constrained_layout? This would be a toggle button - as long as it is active constrained_layout will take effect, but you may toggle it off as well. Not sure what the default state would be though.

  3. ImportanceOfBeingErnest commented on Jul 11, 2018

    Member

    Would it affect animations? Like for each frame that is shown contrained_layout is called? I think that would be completely undesired.

  4. jklymak commented on Jul 11, 2018

    MemberAuthor

    @ImportanceOfBeingErnest and @timhoffm Thanks for your thoughts...

    First, constrained_layout needs to be turned on when the figure is made - it needs more of a tree heirarchy than Matplotlib provides by itself. So a simple GUI toggle doesn't suffice, because you can't go back and remake the figure.

    Programatically, we can turn off constrained_layout at any time with fig.do_constrained_layout(False). Setting it to True will turn it back on.

    We could have an rcParam['constrained_layout.firstdraw_only']. I imagine we could also extend the above so that we could call fig.do_constrained_layout('firstdraw_only') or fig.do_constrained_layout(True, firstdraw_only=True).

    @afvincent was talking about the layout GUI in another thread. I think it'd make sense for the GUI to be different if constrained_layout is on for the figure, allow the constrained_layout margin and pad parameters to be fiddled with, allow toggling constrained_layout as you suggest, and of course allow bailout to tight_layout instead.

    WRT animations: definitely, constrained_layout will cause the axes to be resized while animating. Again, the current solution is to draw the first draw w/ constrained_layout on, and then call fig.do_constrained_layout(False) to turn it off for the animation steps.

  5. ImportanceOfBeingErnest commented on Jul 11, 2018

    Member

    So a simple GUI toggle doesn't suffice, because you can't go back and remake the figure.

    So that button would only appear if you created the figure with contrained_layout turned on.

    Again, the current solution is to draw the first draw w/ constrained_layout on, and then call fig.do_constrained_layout(False) to turn it off for the animation steps.

    Sounds like this needs a chapter in the constrained_layout guide.

  6. jklymak commented on Jul 13, 2018

    MemberAuthor

    OK, for now I think the right thing to do is whats in #11627, which is to turn CL off during ZOOM and PAN GUI events... Ummm, maybe I mixed things, but in #11648 I added a paragraph to the guide about turning CL on and off ie. for animation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: geometry managerLayoutEngine, Constrained layout, Tight layout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL