# Can't display ica.plot\_properties() in a mne.Report

**URL:** <https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012>\
**Category:** Support & Discussions\
**Tags:** preprocessing, visualization, report\
**Created:** [April 19, 2021, 6:51pm UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012 "2021-04-19T18:51:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apoublan](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@apoublan](https://mne.discourse.group/u/apoublan)\
**Post date:** [April 19, 2021, 6:51pm UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012/1 "2021-04-19T18:51:10Z")

</div>

Hi,

I am having a hard time adding a figure from ica.plot\_properties() into a mne.report, here is the error :

```python
AttributeError Traceback (most recent call last)
<ipython-input-20-90570c3b403e> in <module>
     54 with mne.open_report(f_report) as rep:
     55 rep = mne.Report(image_format = 'svg', title = subject)
---> 56 rep.add_figs_to_section(figs = ica_figs, captions = ica_captions, section = 'ICA plotting')
     57 rep.save(f_report, open_browser = True, overwrite = True)
     58 rep.save(f_report[:-2]+'html',open_browser = True, overwrite = True)

~/.virtualenvs/py3.6/lib/python3.6/site-packages/mne/report.py in add_figs_to_section(self, figs, captions, section, scale, image_format, comments, replace)
   1110 img_klass = self._sectionvars[section]
   1111 
-> 1112 img = _fig_to_img(fig, image_format, scale)
   1113 html = image_template.substitute(img=img, id=global_id,
   1114 div_klass=div_klass,

~/.virtualenvs/py3.6/lib/python3.6/site-packages/mne/report.py in _fig_to_img(fig, image_format, scale, **kwargs)
     72 elif not isinstance(fig, Figure):
     73 from .viz.backends.renderer import backend, MNE_3D_BACKEND_TESTING
---> 74 backend._check_3d_figure(figure=fig)
     75 if not MNE_3D_BACKEND_TESTING:
     76 img = backend._take_3d_screenshot(figure=fig)

AttributeError: 'NoneType' object has no attribute '_check_3d_figure'

```

Here is the code to reproduce the error as well as the raw data used (\>100Mo), you can directly see the outputs and the error in the Jupyter Notebook version : [reportError\_code.zip - Google Drive](https://drive.google.com/file/d/1FAeag4_5rr4jlcS5ANpOC0oZo3u14Y3X/view?usp=sharing)

It seems to me that the report function can’t display a figure with multiple axes like ica.plot\_properties(), if I just add an ica.plot\_scores or plot\_components figure with only 1 axe in the report it works fine (example also included in the provided code). Also displaying the figure directly outside of the report works fine.

I can’t figure it out why it displays an error related to a 3D figure but trying to solve this with mne.viz.set\_3d\_backend(“notebook”), and replacing notebook by pyvista or mayavi but none worked…  
Setting matplotlib to qt instead of inline as recommended for Linux users won’t work…  
I also tried updating to the last mne, matplotlib and Ipython version, didn’t work neither…

I am running out of ideas and it seems nobody ever encountered the same problem so if you have any clue I would appreciate !

Cheers,

Arnaud

Config :  
Platform: Linux-4.15.0-141-generic-x86\_64-with-Ubuntu-18.04-bionic  
Python: 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]  
Executable: /home/arnaud/.virtualenvs/py3.6/bin/python  
CPU: x86\_64: 4 cores  
Memory: Unavailable (requires “psutil” package)  
mne: 0.22.1  
numpy: 1.16.2 {blas=openblas, lapack=openblas}  
scipy: 1.5.2  
matplotlib: 3.3.4 {backend=Qt5Agg}

sklearn: 0.23.2  
numba: Not found  
nibabel: Not found  
nilearn: Not found  
dipy: Not found  
cupy: Not found  
pandas: 0.24.2  
mayavi: 4.7.2  
pyvista: 0.29.1 {OpenGL 4.6 (Core Profile) Mesa 20.0.8 via Mesa DRI Intel(R) HD Graphics 620 (KBL GT2)}  
vtk: 9.0.1  
PyQt5: 5.12.1

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [April 20, 2021, 7:29am UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012/2 "2021-04-20T07:29:59Z")

</div>

Hello @apoublan, in principle, adding ICA property plots to the report **should** work; in fact, we’re doing that in the MNE BIDS Pipeline, producing reports like this:

[http://mne.tools/mne-bids-pipeline/examples/ERP\_CORE/sub-015\_ses-ERN\_task-ERN\_proc-ica\_report.html](http://mne.tools/mne-bids-pipeline/examples/ERP_CORE/sub-015_ses-ERN_task-ERN_proc-ica_report.html)

However, we don’t use SVG and we only add one property plot at a time.

I can have a look at your code later.

Best wishes,

Richard

---

<div class="post-metadata">

**Author:** ![apoublan](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@apoublan](https://mne.discourse.group/u/apoublan)\
**Post date:** [April 20, 2021, 9:35am UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012/3 "2021-04-20T09:35:25Z")

</div>

Hello @richard,  
Thanks for the report example !  
I tried in PNG too, same problem and in the example I sent you there is only one EOG component identified so one property plot at a time.

Thanks a lot, let me know.

Best wishes

Arnaud

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [April 20, 2021, 7:29pm UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012/4 "2021-04-20T19:29:51Z")

</div>

`ICA.plot_properties()` returns a **list of figures.** The following MWE based on you code & data works for me:

```python
# %%
import mne

fname = './S01-raw.fif'
raw = mne.io.read_raw_fif(fname, preload=True)

n_components = 0.98
raw_ica = raw.copy().pick_types(eeg=True).filter(l_freq=1, h_freq=40)

ica = mne.preprocessing.ICA(n_components=n_components, method='picard',
                            random_state=11)
ica.fit(raw_ica)

ica_captions = []
ica_figs = []
ica_figs.extend(ica.plot_properties(raw, picks=[0, 1]))
ica_captions.extend(['property 1', 'property 2'])

report = mne.Report(image_format='svg')
report.add_figs_to_section(section='ICA', figs=ica_figs, captions=ica_captions)
report.save('/tmp/foo.html', overwrite=True)

```

---

<div class="post-metadata">

**Author:** ![apoublan](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@apoublan](https://mne.discourse.group/u/apoublan)\
**Post date:** [April 23, 2021, 3:53pm UTC](https://mne.discourse.group/t/cant-display-ica-plot-properties-in-a-mne-report/3012/5 "2021-04-23T15:53:37Z")

</div>

Hi Richard,

I could have a look at your fix, indeed the use of the extend method instead of append to add the list of figures returned by ica.plot\_properties worked out, thank you !

Best,

Arnaud
