Suppressing pyplot figures

External Email - Use Caution

Hello MNE users,

I am seeking help with figuring out how to prevent the figures from
displaying when using this function:
https://martinos.org/mne/stable/generated/mne.viz.plot_topomap.html#mne.viz.plot_topomap

In using this mne.viz.plot_topomap, my aim is to save out the figure as a
.png without it opening in a new window and without me having to manually
close the figure. Here is how I am using the function:

fig_a=plt.figure()
mne.viz.plot_topomap(data_array,
pos=mne.channels.read_montage('biosemi64').pos[:64,:2])
plt.close(fig_a)
fig_a.savefig('/home/dcellier/data_array_topoplot.png')

The result is that the topomap figure is popping up and pauses the script
until I close it. This is problematic because this code is nested in a for
loop and will be called upon >100 times. It does successfully save the
topomap in the intended directory.

What I've tried, to no avail:

import matplotlib.pyplot as plt
plt.ioff() #turning interactive plotter off
print(matplotlib.is_interactive()) #returns False
matplotlib.use('Agg')

as well as plt.close(). I also tried assigning the output of
mne.viz.plot_topomap() to a variable, but it doesn't work to suppress the
figure.

Thank you in advance for any assistance!!

Best wishes,
Dillan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190627/e367c3cc/attachment.html

External Email - Use Caution

Hi Dillan,

Did you try using the show parameter that is provided with plot_topomap
function? You should set it to False so that plt.show() is not called by
MNE.

The other option is to call matplotlib.use('Agg') at the very top of your
script before any imports. The only thing you can import before that is import
matplotlib.

Hope that helps,
Mainak