Skip to content

Commit 885b6fd

Browse files
committed
FIX: Animations should disable savefig.bbox as necessary.
This fixes part of #6416 by resetting the 'savefig.bbox' rcParam if it is set to 'tight'.
1 parent 949ecdd commit 885b6fd

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

lib/matplotlib/animation.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from matplotlib.cbook import iterable, is_string_like
4040
from matplotlib.compat import subprocess
4141
from matplotlib import verbose
42-
from matplotlib import rcParams, rcParamsDefault
42+
from matplotlib import rcParams, rcParamsDefault, rc_context
4343

4444
# Process creation flag for subprocess to prevent it raising a terminal
4545
# window. See for example:
@@ -801,17 +801,26 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
801801
# frame information to be saved later.
802802
# TODO: Right now, after closing the figure, saving a movie won't work
803803
# since GUI widgets are gone. Either need to remove extra code to
804-
# allow for this non-existant use case or find a way to make it work.
805-
with writer.saving(self._fig, filename, dpi):
806-
for anim in all_anim:
807-
# Clear the initial frame
808-
anim._init_draw()
809-
for data in zip(*[a.new_saved_frame_seq()
810-
for a in all_anim]):
811-
for anim, d in zip(all_anim, data):
812-
# TODO: Need to see if turning off blit is really necessary
813-
anim._draw_next_frame(d, blit=False)
814-
writer.grab_frame(**savefig_kwargs)
804+
# allow for this non-existent use case or find a way to make it work.
805+
with rc_context():
806+
# See above about bbox_inches savefig kwarg
807+
if (not writer.frame_size_can_vary and
808+
rcParams['savefig.bbox'] == 'tight'):
809+
verbose.report("Disabling savefig.bbox = 'tight', as it is "
810+
"not supported by "
811+
"{0}.".format(writer.__class__.__name__),
812+
level='helpful')
813+
rcParams['savefig.bbox'] = None
814+
with writer.saving(self._fig, filename, dpi):
815+
for anim in all_anim:
816+
# Clear the initial frame
817+
anim._init_draw()
818+
for data in zip(*[a.new_saved_frame_seq()
819+
for a in all_anim]):
820+
for anim, d in zip(all_anim, data):
821+
# TODO: See if turning off blit is really necessary
822+
anim._draw_next_frame(d, blit=False)
823+
writer.grab_frame(**savefig_kwargs)
815824

816825
# Reconnect signal for first draw if necessary
817826
if reconnect_first_draw:

0 commit comments

Comments
 (0)