Programmatically Choose Correct Backend For Matplotlib On Mac Os X
I have a program which integrates a tkinter GUI as well as a matplotlib plot (using pyplot). I'm running into endless troubles having this program work correctly across a variety o
Solution 1:
See this answer: How to switch backends in matplotlib / Python
In essence, if you do not know which backend
is available, the following code should load up the first backend
that is available on the current machine. (I have only included 4 backends, there are quite a few others).
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
breakexcept:
continueprint("Using:",matplotlib.get_backend())
Using: GTKAgg
Update: I am lead to believe that there is a backend for OSX called MacOSX
which could be added to that list, although I have no way of testing it myself.
Post a Comment for "Programmatically Choose Correct Backend For Matplotlib On Mac Os X"