Skip to content

Commit df92ada

Browse files
committed
Get topmost gridspec from figure
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.
1 parent c353bc9 commit df92ada

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

animatplot/animation.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def _controls_gridspec(self):
6969

7070
controls_height = 0.2
7171

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

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

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

0 commit comments

Comments
 (0)