# Is it possible to append new figure to an	existing html generated by mne.report module

**URL:** <https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2299>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [August 27, 2020, 3:01am UTC](https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2299 "2020-08-27T03:01:52Z")\
**Posts on this page:** 1\
**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:** [August 27, 2020, 3:01am UTC](https://mne.discourse.group/t/is-it-possible-to-append-new-figure-to-an-existing-html-generated-by-mne-report-module/2299/1 "2020-08-27T03:01:52Z")

</div>

External Email - Use Caution

Hi Marijin,  
Thanks for the suggestion it really help. +1 for the "conpy" analysis  
pipeline and your paper.

As per suggestion by Marijin, the code to append existing mne report and  
customise html is as below:

Regards  
Rodney

Code:

import mne  
from mne.datasets import sample  
from mne.report import Report

data\_path = sample.data\_path()  
raw\_fname = data\_path + '/MEG/sample/sample\_audvis\_raw.fif'  
raw = mne.io.read\_raw\_fif(raw\_fname, preload=True)

def first\_run():  
&nbsp;&nbsp;&nbsp;&nbsp;raw1 = raw.copy().crop(0, 20)

&nbsp;&nbsp;&nbsp;&nbsp;raw1.save(data\_path + '/MEG/sample/sub-01\_raw.fif', overwrite=True)

&nbsp;&nbsp;&nbsp;&nbsp;event\_id = {'Auditory/Left': 3, 'Auditory/Right': 4}

&nbsp;&nbsp;&nbsp;&nbsp;def raw\_to\_evoked(raw\_fname, tmin=-0.1, tmax=0.5):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw = mne.io.read\_raw\_fif(data\_path + '/MEG/sample/' + raw\_fname,  
preload=True)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;raw.filter(0, 40.)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;events = mne.find\_events(raw, stim\_channel='STI 014')  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;epochs = mne.Epochs(raw, events, event\_id, tmin, tmax)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig2 = epochs.plot();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evoked\_l = epochs['Left'].average();  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig3 = evoked\_l.plot\_topomap()  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fig4 = evoked\_l.plot();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [fig2, fig3, fig4]

&nbsp;&nbsp;&nbsp;&nbsp;rep = Report()  
&nbsp;&nbsp;&nbsp;&nbsp;figs = raw\_to\_evoked('sub-01\_raw.fif')  
&nbsp;&nbsp;&nbsp;&nbsp;rep.add\_figs\_to\_section(figs , captions=['Epochs', 'Topomap',  
'Butterfly'])  
&nbsp;&nbsp;&nbsp;&nbsp;rep.save('my\_report.h5')

def second\_run():  
&nbsp;&nbsp;&nbsp;&nbsp;fig1 = raw.plot()  
&nbsp;&nbsp;&nbsp;&nbsp;html = """  
&nbsp;&nbsp;&nbsp;&nbsp;\<table class="table table-hover"\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<tr\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<th\>Meas time range\</th\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<th\>Sampling freq\</th\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</tr\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<tr\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td\> %0.2f to %0.2f \</td\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<td\> %0.2f \</td\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\</tr\>  
&nbsp;&nbsp;&nbsp;&nbsp;\</table\>  
&nbsp;&nbsp;&nbsp;&nbsp;"""  
&nbsp;&nbsp;&nbsp;&nbsp;with mne.open\_report('my\_report.h5') as rep:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Append new figure to the existing report  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rep.add\_figs\_to\_section(fig1,captions=['raw'])  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# add custom htmls  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rep.add\_htmls\_to\_section(html % (raw.times[0], raw.times[-1],  
raw.info['sfreq']), captions='Info table')

rep.save('report\_raw\_to\_second\_run.html',overwrite=True,open\_browser=False)

first\_run()  
second\_run()
