Skip to content

Commit

Permalink
Get topmost gridspec from figure
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnomotani committed Dec 19, 2019
1 parent c353bc9 commit df92ada
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions animatplot/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ def _controls_gridspec(self):

controls_height = 0.2

# get gridspec to adjust
gs = (plt.gca().get_gridspec().get_topmost_subplotspec()
.get_gridspec())
fig_gridspecs = self.fig._gridspecs
if len(fig_gridspecs) > 1:
raise ValueError('multiple gridspecs found in figure')
gs = fig_gridspecs[0]
nrows, ncols = gs.get_geometry()
height_ratios = gs.get_height_ratios()

Expand Down Expand Up @@ -112,6 +113,9 @@ def toggle(self, ax=None):
except:
# editing the gridspec did not work for some reason, fall back to
# subplots_adjust
print('warning: adding play/pause button to gridspec failed, '
'adding in independent axes. tight_layout() will ignore '
'the button.')
adjust_plot = {'bottom': .2}
rect = [.78, .03, .1, .07]

Expand Down Expand Up @@ -167,6 +171,9 @@ def timeline_slider(self, text='Time', ax=None, valfmt=None, color=None):
except:
# editing the gridspec did not work for some reason, fall back to
# subplots_adjust
print('warning: adding timeline slider to gridspec failed, '
'adding in independent axes. tight_layout() will ignore '
'the slider.')
adjust_plot = {'bottom': .2}
rect = [.18, .05, .5, .03]
plt.subplots_adjust(**adjust_plot)
Expand Down

0 comments on commit df92ada

Please sign in to comment.