Skip to content

Commit c92e48b

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 c92e48b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/matplotlib/backend_bases.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,7 @@ def __init__(self, figure):
17721772
self._is_saving = False
17731773
figure.set_canvas(self)
17741774
self.figure = figure
1775+
self.manager = None
17751776
# a dictionary from event name to a dictionary that maps cid->func
17761777
self.callbacks = cbook.CallbackRegistry()
17771778
self.widgetlock = widgets.LockDraw()
@@ -2149,6 +2150,15 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
21492150
21502151
"""
21512152
self._is_saving = True
2153+
# Remove the figure manager, if any, to avoid resizing the GUI widget.
2154+
# Having *no* manager and a *None* manager are currently different (see
2155+
# Figure.show); should probably be normalized to None at some point.
2156+
_no_manager = object()
2157+
if hasattr(self, 'manager'):
2158+
manager = self.manager
2159+
del self.manager
2160+
else:
2161+
manager = _no_manager
21522162

21532163
if format is None:
21542164
# get format from filename, or from backend's default filetype
@@ -2267,8 +2277,9 @@ def print_figure(self, filename, dpi=None, facecolor=None, edgecolor=None,
22672277
self.figure.set_facecolor(origfacecolor)
22682278
self.figure.set_edgecolor(origedgecolor)
22692279
self.figure.set_canvas(self)
2280+
if manager is not _no_manager:
2281+
self.manager = manager
22702282
self._is_saving = False
2271-
#self.figure.canvas.draw() ## seems superfluous
22722283
return result
22732284

22742285
@classmethod

0 commit comments

Comments
 (0)