File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,27 @@ def _destroy_on_hotkey(event):
83
83
84
84
# remove this callback. Callbacks live on the Figure so survive the canvas
85
85
# being replaced.
86
- fig .canvas .mpl_connect ("key_press_event" , _destroy_on_hotkey )
86
+ fig ._destroy_cid = fig . canvas .mpl_connect ("key_press_event" , _destroy_on_hotkey )
87
87
88
88
return manager
89
+
90
+
91
+ def demote_figure (fig ):
92
+ """Fully clear all GUI elements from the `~matplotlib.figure.Figure`.
93
+
94
+ The opposite of what is done during `mpl_gui.display`.
95
+
96
+ Parameters
97
+ ----------
98
+ fig : matplotlib.figure.Figure
99
+
100
+ """
101
+ fig .canvas .destroy ()
102
+ fig .canvas .manager = None
103
+ original_dpi = getattr (fig , "_original_dpi" , fig .dpi )
104
+ if (cid := getattr (fig , '_destroy_cid' , None )) is not None :
105
+ fig .canvas .mpl_disconnect (cid )
106
+ FigureCanvasBase (fig )
107
+ fig .dpi = original_dpi
108
+
109
+ return fig
You can’t perform that action at this time.
0 commit comments