Skip to content

Commit a6b34d4

Browse files
committed
Unset the canvas manager when saving the figure.
Saving a figure may involve temporarily resizing the canvas (e.g. due to different dpi), but we don't want that resize to be propagated to the actual GUI widget. Ensure this by temporarily unsetting the manager as well.
1 parent 4753f6c commit a6b34d4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/matplotlib/backend_bases.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,15 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
21492149
21502150
"""
21512151
self._is_saving = True
2152+
# Remove the figure manager, if any, to avoid resizing the GUI widget.
2153+
# Having *no* manager and a *None* manager are currently different (see
2154+
# Figure.show); should probably be normalized to None at some point.
2155+
_no_manager = object()
2156+
if hasattr(self, 'manager'):
2157+
manager = self.manager
2158+
del self.manager
2159+
else:
2160+
manager = _no_manager
21522161

21532162
if format is None:
21542163
# get format from filename, or from backend's default filetype
@@ -2267,8 +2276,9 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
22672276
self.figure.set_facecolor(origfacecolor)
22682277
self.figure.set_edgecolor(origedgecolor)
22692278
self.figure.set_canvas(self)
2279+
if manager is not _no_manager:
2280+
self.manager = manager
22702281
self._is_saving = False
2271-
#self.figure.canvas.draw() ## seems superfluous
22722282
return result
22732283

22742284
@classmethod

0 commit comments

Comments
 (0)