From 99a2e462c669add554bf7e88b627990771ecf356 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Wed, 5 Sep 2018 11:58:37 +0200 Subject: [PATCH] Remove intent to deprecate rcParams["backend_fallback"]. I had left a note intending to deprecate this rcParam back when the backend-switching API would let the user specify an explicit fallback list. As this feature was not accepted, it makes sense to keep the rcparam. Also move its actual use next to the place where the backend is set up in pyplot.py. Also move the call to install_repl_displayhook after that, as install_repl_displayhook calls get_backend() so we want the rcparam to have taken effect already. --- lib/matplotlib/pyplot.py | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 021f28f804b3..c78334da153a 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -72,26 +72,6 @@ _log = logging.getLogger(__name__) -## Backend detection ## - - -# FIXME: Deprecate. -def _backend_selection(): - """ - If rcParams['backend_fallback'] is true, we will check (at backend - load-time) to see if the current backend is compatible with the current - running event loop, and if not switches to a compatible one. - """ - if rcParams["backend_fallback"]: - if (dict.__getitem__(rcParams, "backend") in _interactive_bk - and _get_running_interactive_framework()): - dict.__setitem__( - rcParams, "backend", rcsetup._auto_backend_sentinel) - - -_backend_selection() - - ## Global ## @@ -2348,16 +2328,23 @@ def _autogen_docstring(base): return lambda func: addendum(docstring.copy_dedent(base)(func)) -# just to be safe. Interactive mode can be turned on without +# If rcParams['backend_fallback'] is true, and an interactive backend is +# requested, ignore rcParams['backend'] and force selection of a backend that +# is compatible with the current running interactive framework. +if (rcParams["backend_fallback"] + and dict.__getitem__(rcParams, "backend") in _interactive_bk + and _get_running_interactive_framework()): + dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel) +# Set up the backend. +switch_backend(rcParams["backend"]) + +# Just to be safe. Interactive mode can be turned on without # calling `plt.ion()` so register it again here. # This is safe because multiple calls to `install_repl_displayhook` # are no-ops and the registered function respect `mpl.is_interactive()` # to determine if they should trigger a draw. install_repl_displayhook() -# Set up the backend. -switch_backend(rcParams["backend"]) - ################# REMAINING CONTENT GENERATED BY boilerplate.py ##############