# Suppressing pyplot figures

**URL:** <https://mne.discourse.group/t/suppressing-pyplot-figures/1881>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [June 27, 2019, 8:05pm UTC](https://mne.discourse.group/t/suppressing-pyplot-figures/1881 "2019-06-27T20:05:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [June 27, 2019, 8:05pm UTC](https://mne.discourse.group/t/suppressing-pyplot-figures/1881/1 "2019-06-27T20:05:49Z")

</div>

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](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](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20190627/e367c3cc/attachment.html)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [June 27, 2019, 9:44pm UTC](https://mne.discourse.group/t/suppressing-pyplot-figures/1881/2 "2019-06-27T21:44:57Z")

</div>

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
