Skip to content

Instantly share code, notes, and snippets.

@AngelBerihuete
Created February 27, 2019 08:50
Show Gist options
  • Save AngelBerihuete/01b0ddd4e67a0ab5599e7d7f26f8a9f4 to your computer and use it in GitHub Desktop.
Save AngelBerihuete/01b0ddd4e67a0ab5599e7d7f26f8a9f4 to your computer and use it in GitHub Desktop.
# This file was obtained from StackOverflow:
#
# How to switch backends in matplotlib / Python
# https://stackoverflow.com/questions/3285193/how-to-switch-backends-in-matplotlib-python
import matplotlib
gui_env = ['TKAgg','GTKAgg','Qt4Agg','WXAgg']
for gui in gui_env:
try:
print("testing", gui)
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:",matplotlib.get_backend())
import matplotlib
gui_env = [i for i in matplotlib.rcsetup.interactive_bk]
non_gui_backends = matplotlib.rcsetup.non_interactive_bk
print ("Non Gui backends are:", non_gui_backends)
print ("Gui backends I will test for", gui_env)
for gui in gui_env:
print ("testing", gui)
try:
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
print (" ",gui, "Is Available")
plt.plot([1.5,2.0,2.5])
fig = plt.gcf()
fig.suptitle(gui)
plt.show()
print ("Using ..... ",matplotlib.get_backend())
except:
print (" ",gui, "Not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment