Skip to content

Commit d0958e4

Browse files
committed
Fix: properly decouple from pyplot and specific backends when destroying
When destroying a manager, replace the figure's canvas by a figure canvas base.
1 parent c718eae commit d0958e4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ def show(self):
664664
self.window.raise_()
665665

666666
def destroy(self, *args):
667+
self.canvas.figure._set_base_canvas()
667668
# check for qApp first, as PySide deletes it in its atexit handler
668669
if QtWidgets.QApplication.instance() is None:
669670
return

lib/matplotlib/figure.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ def __init__(self,
26422642
self._set_artist_props(self.patch)
26432643
self.patch.set_antialiased(False)
26442644

2645-
FigureCanvasBase(self) # Set self.canvas.
2645+
self._set_base_canvas()
26462646

26472647
if subplotpars is None:
26482648
subplotpars = SubplotParams()
@@ -2996,6 +2996,15 @@ def get_constrained_layout_pads(self, relative=False):
29962996

29972997
return w_pad, h_pad, wspace, hspace
29982998

2999+
def _set_base_canvas(self):
3000+
"""
3001+
Initialize self.canvas with a FigureCanvasBase instance.
3002+
3003+
This is used upon initialization of the Figure, but also
3004+
to reset the canvas when decoupling from pyplot.
3005+
"""
3006+
FigureCanvasBase(self) # Set self.canvas as a side-effect
3007+
29993008
def set_canvas(self, canvas):
30003009
"""
30013010
Set the canvas that contains the figure

0 commit comments

Comments
 (0)