Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35e792f

Browse files
committed
fix #2005: Animated artists should be included when saving to a file
1 parent 616efcf commit 35e792f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/matplotlib/axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,11 @@ def draw(self, renderer=None, inframe=False):
20142014
if self.axison and self._frameon:
20152015
artists.extend(self.spines.itervalues())
20162016

2017-
dsu = [ (a.zorder, a) for a in artists
2018-
if not a.get_animated() ]
2017+
if self.figure.canvas.is_saving():
2018+
dsu = [(a.zorder, a) for a in artists]
2019+
else:
2020+
dsu = [(a.zorder, a) for a in artists
2021+
if not a.get_animated()]
20192022

20202023
# add images to dsu if the backend support compositing.
20212024
# otherwise, does the manaul compositing without adding images to dsu.

lib/matplotlib/backend_bases.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,13 +1485,21 @@ def __init__(self, figure):
14851485
self.scroll_pick_id = self.mpl_connect('scroll_event',self.pick)
14861486
self.mouse_grabber = None # the axes currently grabbing mouse
14871487
self.toolbar = None # NavigationToolbar2 will set me
1488+
self._is_saving = False
14881489
if False:
14891490
## highlight the artists that are hit
14901491
self.mpl_connect('motion_notify_event',self.onHilite)
14911492
## delete the artists that are clicked on
14921493
#self.mpl_disconnect(self.button_pick_id)
14931494
#self.mpl_connect('button_press_event',self.onRemove)
14941495

1496+
def is_saving(self):
1497+
"""
1498+
Returns `True` when the renderer is in the process of saving
1499+
to a file, rather than rendering for an on-screen buffer.
1500+
"""
1501+
return self._is_saving
1502+
14951503
def onRemove(self, ev):
14961504
"""
14971505
Mouse event processor which removes the top artist
@@ -2096,6 +2104,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
20962104
else:
20972105
_bbox_inches_restore = None
20982106

2107+
self._is_saving = True
20992108
try:
21002109
#result = getattr(self, method_name)(
21012110
result = print_method(
@@ -2114,6 +2123,7 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
21142123
self.figure.set_facecolor(origfacecolor)
21152124
self.figure.set_edgecolor(origedgecolor)
21162125
self.figure.set_canvas(self)
2126+
self._is_saving = False
21172127
#self.figure.canvas.draw() ## seems superfluous
21182128
return result
21192129

@@ -2160,6 +2170,7 @@ def switch_backends(self, FigureCanvasClass):
21602170
figure size or line props), will be reflected in the other
21612171
"""
21622172
newCanvas = FigureCanvasClass(self.figure)
2173+
newCanvas._is_saving = self._is_saving
21632174
return newCanvas
21642175

21652176
def mpl_connect(self, s, func):

0 commit comments

Comments
 (0)