@@ -104,6 +104,15 @@ def _copy_docstring_and_deprecators(method, func=None):
104
104
105
105
## Global ##
106
106
107
+ def _initial_switch_backend ():
108
+ switch_backend (dict .__getitem__ (rcParams , "backend" ))
109
+ # Just to be safe. Interactive mode can be turned on without
110
+ # calling `plt.ion()` so register it again here.
111
+ # This is safe because multiple calls to `install_repl_displayhook`
112
+ # are no-ops and the registered function respect `mpl.is_interactive()`
113
+ # to determine if they should trigger a draw.
114
+ install_repl_displayhook ()
115
+
107
116
108
117
_IP_REGISTERED = None
109
118
_INSTALL_FIG_OBSERVER = False
@@ -289,9 +298,13 @@ class backend_mod(matplotlib.backend_bases._Backend):
289
298
# Need to keep a global reference to the backend for compatibility reasons.
290
299
# See https://github.com/matplotlib/matplotlib/issues/6092
291
300
matplotlib .backends .backend = newbackend
301
+ switch_backend ._ever_called = True
302
+ switch_backend ._ever_called = False
292
303
293
304
294
305
def _warn_if_gui_out_of_main_thread ():
306
+ if not switch_backend ._ever_called :
307
+ _initial_switch_backend ()
295
308
if (_get_required_interactive_framework (_backend_mod )
296
309
and threading .current_thread () is not threading .main_thread ()):
297
310
_api .warn_external (
@@ -316,6 +329,8 @@ def draw_if_interactive(*args, **kwargs):
316
329
End users will typically not have to call this function because the
317
330
the interactive mode takes care of this.
318
331
"""
332
+ if not switch_backend ._ever_called :
333
+ _initial_switch_backend ()
319
334
return _backend_mod .draw_if_interactive (* args , ** kwargs )
320
335
321
336
@@ -2229,15 +2244,6 @@ def polar(*args, **kwargs):
2229
2244
set (_interactive_bk ) - {'WebAgg' , 'nbAgg' })
2230
2245
and cbook ._get_running_interactive_framework ()):
2231
2246
dict .__setitem__ (rcParams , "backend" , rcsetup ._auto_backend_sentinel )
2232
- # Set up the backend.
2233
- switch_backend (rcParams ["backend" ])
2234
-
2235
- # Just to be safe. Interactive mode can be turned on without
2236
- # calling `plt.ion()` so register it again here.
2237
- # This is safe because multiple calls to `install_repl_displayhook`
2238
- # are no-ops and the registered function respect `mpl.is_interactive()`
2239
- # to determine if they should trigger a draw.
2240
- install_repl_displayhook ()
2241
2247
2242
2248
2243
2249
################# REMAINING CONTENT GENERATED BY boilerplate.py ##############
0 commit comments