You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Recompute figsize-dependent parameters on resize #5824
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).
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 afterresize_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.
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.
Activity
tacaswell commentedon Jan 10, 2016
#5772 re-computes the number of ticks on the fly
anntzer commentedon Jun 7, 2016
Actually, manually adding the callback is as simple as
so just a note in the docs may be enough.
Edit: However, it appears that connecting to
draw_eventinstead does not work -- thetight_layoutseems to be computed based on the previous window size instead. This is a bit unexpected asdraw_eventis triggered afterresize_event(as can be checked by instrumenting the callback registry), so if anything you'd expect the new size to be known by the timedraw_eventis emitted...anntzer commentedon Oct 25, 2016
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.