From 021523798940d8a4c52f2dd29183f073627ec7ac Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 20 May 2019 18:50:02 -0400 Subject: [PATCH] Backport PR #14279: In case fallback to Agg fails, let the exception propagate out. --- lib/matplotlib/pyplot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index dcf13ec7d92f..d3e8a3379502 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -198,8 +198,8 @@ def switch_backend(newbackend): # Don't try to fallback on the cairo-based backends as they each have # an additional dependency (pycairo) over the agg-based backend, and # are of worse quality. - for candidate in ["macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", - "wxagg", "agg"]: + for candidate in [ + "macosx", "qt5agg", "qt4agg", "gtk3agg", "tkagg", "wxagg"]: try: switch_backend(candidate) except ImportError: @@ -207,6 +207,12 @@ def switch_backend(newbackend): else: rcParamsOrig['backend'] = candidate return + else: + # Switching to Agg should always succeed; if it doesn't, let the + # exception propagate out. + switch_backend("agg") + rcParamsOrig["backend"] = "agg" + return backend_name = ( newbackend[9:] if newbackend.startswith("module://")