easybuild icon indicating copy to clipboard operation
easybuild copied to clipboard

Matplotlib Agg backend

Open hattom opened this issue 4 years ago • 0 comments

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?

  • Thomas

[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)

hattom avatar Jan 10 '22 11:01 hattom