I\'m generating matplotlib figures in a script which I run alternatively with or without a graphical display. I\'d like the script to adjust automatically: with display, it
when use GUI backend the figure object has show() method, you can use it to do the switch:
import matplotlib #matplotlib.use("Agg") import matplotlib.pyplot as plt fig = plt.figure() havedisplay = False if hasattr(fig, "show"): plt.show() else: print "save fig" fig.savefig("myfig.png")