[Mne_analysis] How to save figures in a loop without displaying them?

Maria Hakonen maria.hakonen at gmail.com
Sun Aug 17 04:06:54 EDT 2014
Search archives:

Hi,

Thanks for the answer.
However, the script seems to run very long time if ipython is started
without --pylab qt flag. I wonder if there is any other ways to save the
figures in the loop without displaying them?

Regards,
Maria


2014-08-16 21:27 GMT+03:00 Denis-Alexander Engemann <
denis.engemann at gmail.com>:

> Hi Maria,
>
>
> just use ```plt.close('all')```.
>
> I would recommend to add the following two lines at the top of your script
> :
>
> import matplotlib
> matplotlib.use('Agg')
>
> This will invoke matplotibs silent mode in which the figures are produced
> but not shown.
>
> With this addition you have to start ipython without --pylab flag because
> the backend has to be set first.
>
> HTH,
> Denis
>
>
>
> On Sat, Aug 16, 2014 at 8:20 PM, Maria Hakonen <maria.hakonen at gmail.com>
> wrote:
>
>> Hi all,
>>
>> I would like to remove eog artifacts from several files in a loop using
>> ica and save some plots of the ica results without displaying them while
>> the loop is running. I have tried this as follows:
>>
>> subjects = ['av','li','kk','mh','ml']
>> for s in range(0,5):
>>         sessions = ['_s1','_s2','_s3']
>>         for x in range(0, 3):
>>                 ...
>>
>>                 fig = ica.plot_scores(scores, exclude=eog_inds)
>>                 file_end= 'scores.png'
>>                 filename = subjects[s]+sessions[x]+file_end
>>                 plt.savefig(filename)
>>                 plt.close(fig)
>>
>>                 fig=ica.plot_sources(epochs_bp,eog_inds)
>>                 file_end = 'sources.png'
>>                 filename = subjects[s]+sessions[x]+file_end
>>                 plt.savefig(filename)
>>                 plt.close(fig)
>>
>>                 fig=ica.plot_components(eog_inds, colorbar=True)
>>                 file_end = 'components.png'
>>                 filename = subjects[s]+sessions[x]+file_end
>>                 plt.savefig(filename)
>>                 plt.close(fig)
>>                 ica.exclude += eog_inds[:1]
>>                  ...
>>
>> However, I get errors pasted below. They seem to come from
>> plt.close(fig). Could somebody please let me know what I am doing wrong.
>> Thanks already in advance!
>>
>> RuntimeError                              Traceback (most recent call
>> last)
>> /usr/lib/pymodules/python2.7/matplotlib/backends/backend_qt4.pyc in
>> <lambda>()
>>     149         #    self.close_event)
>>
>>     150         QtCore.QObject.connect(self, QtCore.SIGNAL('destroyed()'),
>> --> 151                                lambda: self.close_event())
>>     152
>>     153     def __timerEvent(self, event):
>>
>> /usr/lib/pymodules/python2.7/matplotlib/backend_bases.pyc in
>> close_event(self, guiEvent)
>>    1562         try:
>>    1563             event = CloseEvent(s, self, guiEvent=guiEvent)
>> -> 1564             self.callbacks.process(s, event)
>>    1565         except TypeError:
>>    1566             pass
>>
>> RuntimeError: underlying C/C++ object has been deleted
>>
>> Best Regards,
>> Maria
>>
>>
>>
>> _______________________________________________
>> Mne_analysis mailing list
>> Mne_analysis at nmr.mgh.harvard.edu
>> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>>
>>
>> The information in this e-mail is intended only for the person to whom it
>> is
>> addressed. If you believe this e-mail was sent to you in error and the
>> e-mail
>> contains patient information, please contact the Partners Compliance
>> HelpLine at
>> http://www.partners.org/complianceline . If the e-mail was sent to you
>> in error
>> but does not contain patient information, please contact the sender and
>> properly
>> dispose of the e-mail.
>>
>>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
> The information in this e-mail is intended only for the person to whom it
> is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> contains patient information, please contact the Partners Compliance
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in
> error
> but does not contain patient information, please contact the sender and
> properly
> dispose of the e-mail.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140817/a157d737/attachment.html 


More information about the Mne_analysis mailing list