diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 0c7893b81977..605212c75bfb 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -3523,6 +3523,9 @@ class Show(ShowBase): def mainloop(self): return cls.mainloop() + if not hasattr(sys.modules[cls.__module__], "Backend"): + setattr(sys.modules[cls.__module__], "Backend", cls) + setattr(sys.modules[cls.__module__], "Show", Show) return cls diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 45e40feeef54..67e27a9c85ff 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -269,8 +269,16 @@ def switch_backend(newbackend): backend_name = cbook._backend_module_name(newbackend) - class backend_mod(matplotlib.backend_bases._Backend): - locals().update(vars(importlib.import_module(backend_name))) + backend_mod = importlib.import_module(backend_name) + if hasattr(backend_mod, "Backend"): + backend_mod = backend_mod.Backend + else: + class backend_mod(matplotlib.backend_bases._Backend): + locals().update(vars(backend_mod)) + + @classmethod + def mainloop(cls): + return backend_mod.Show().mainloop() required_framework = _get_required_interactive_framework(backend_mod) if required_framework is not None:
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: