easybuilders / easybuild

EasyBuild - building software with ease
http://easybuild.io
GNU General Public License v2.0
464 stars 143 forks source link

Matplotlib Agg backend #772

Open hattom opened 2 years ago

hattom commented 2 years ago

EB sets MPLBACKEND to Agg by default to give a non-interactive backend. Whilst this solves the problem of "why won't my matplotlib work in the batch system" [1], it leads to the trickier problem of "how to get matplotlib to be interactive when I want to use it interactively?" [2].

According to the Slack discussion, https://github.com/matplotlib/matplotlib/pull/17396 pulled in a improved matplotlib backend fallback since v3.3.3.

Is this something that could be changed?

[1] one for which people are often accustomed and have good workarounds [2] My personal approach to support EB's matplotlib now looks something like this. I'm sure there's a better way, but I don't know what it is.

from os import environ
import matplotlib
if 'DISPLAY' not in environ:
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt 
else:
    import matplotlib.pyplot as plt 
    if not matplotlib.is_interactive():
        plt.switch_backend(matplotlib.rcsetup._auto_backend_sentinel)