From 6c94fc8631d9707dba1f010adc99c05647fc1eff Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 20 May 2019 21:42:38 +0200 Subject: [PATCH] In case fallback to Agg fails, let the exception propagate out. ... as there's likely something very wrong with the user's install. --- 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 4f266917e47f..ffb1ca690ed0 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://")