Skip to content

Recompute figsize-dependent parameters on resize #5824

Closed

Description

@anntzer

Edit: See #5824 (comment) for the doc related issue.

Currently, applying tight_layout and resizing the figure do not commute (e.g., after subplots(2); tight_layout() and a manual maximization of the figure size, applying tight_layout again changes the margins). This is basically due to the fact that certain paddings (and text sizes) are in absolute units, which is fairly reasonable.

However, it would be nice if an option was available to add a callback to figure resize events to auto-re-tightlayout when that happens.

The following part is solved by the yet-to-be-merged #5772.
This kind of feature may become even more useful now that #5588 (number of ticks determined from physical length of axis) has been merged, as the number of ticks should, well, also be adjusted when the figure is resized (or rather, the option to do so should be (easily) available).

Activity

  1. tacaswell commented on Jan 10, 2016

    @tacaswell
    Member

    #5772 re-computes the number of ticks on the fly

  2. added this to the milestone on Jan 10, 2016
  3. anntzer commented on Jun 7, 2016

    @anntzer
    ContributorAuthor

    Actually, manually adding the callback is as simple as

    fig.canvas.mpl_connect("resize_event", lambda _: fig.tight_layout())
    

    so just a note in the docs may be enough.

    Edit: However, it appears that connecting to draw_event instead does not work -- the tight_layout seems to be computed based on the previous window size instead. This is a bit unexpected as draw_event is triggered after resize_event (as can be checked by instrumenting the callback registry), so if anything you'd expect the new size to be known by the time draw_event is emitted...

    (I am a bit confused as to why the callback (to which no other reference is kept) does not get garbage collected though. I never really liked the fact that only a weakref is kept to callbacks so I'm not complaining about it... just asking.)

    Edit: Because weakref'ing is only used for actual methods that are used as callbacks. Ugh.

  4. anntzer commented on Oct 25, 2016

    @anntzer
    ContributorAuthor

    Actually, even better is to just use fig.set_tight_layout(), or the rcparam associated with it. This could be mentioned in the tight layout guide (http://matplotlib.org/devdocs/users/tight_layout_guide.html), so I'm turning this into a doc issue.

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