Skip to content

Conversation

johnomotani
Copy link
Contributor

This PR attempts to make the animation controls (time-slider and play/pause button) compatible with use of tight_layout().

Previously, calling tight_layout could arrange the animations in a figure, but would not move or take into account the controls, which would end up overlapping the lower part of the animations.

This PR seems to work, but requires accessing a private variable of matplotlib.figure.Figure to get the gridspec, in order to modify it to add the controls. Also modifies a private member of matplotlib.gridspec.Gridspec to modify the number of rows. It would be nice if matplotlib provided public methods to access and update gridspecs, but as far as I can see they do not at the moment.

One issue is that the current implementation seems to reserve too much whitespace around the controls. It would be nice to find a way to allow tight_layout() to modify the amount of space above/below the slider.

Makes control placement compatible with tight_layout() method or
constrained_layout option. Falls back on previous absolute placement
method if the gridspec version fails for any reason.
Previously was getting gridspec from current axes. This could result in
getting only a subplot, not the top gridspec from the figure. Workaround
depends on interal _gridspecs member of Figure, which is not ideal but
support for editing existing gridspecs in matplotlib is non-existant.
@johnomotani
Copy link
Contributor Author

The vertical spacing around the controls is set when the sub-grids are created here

button_gridspec = button_subplotspec.subgridspec(
3, 3, width_ratios=[0.45, 0.45, 0.1],
height_ratios=[.05, .5, .45], wspace=0., hspace=0.)

and here
slider_gridspec = slider_subplotspec.subgridspec(
3, 1, height_ratios=[.2, .2, .6], wspace=0.,
hspace=0.)

I guess the problem is that tight_layout cannot change these numbers, but I don't know how to create the slider or button axes in a different way so that it can modify their spacing and position.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant