MNE-report integration with 3D viz is broken
See original GitHub issueWhen I do the following:
import os
import os.path as op
import numpy as np
import matplotlib.pyplot as plt
from mayavi import mlab
import mne
from mne.viz import use_3d_backend
from mne.datasets import sample
data_path = sample.data_path()
sample_dir = os.path.join(data_path, 'MEG', 'sample')
subjects_dir = os.path.join(data_path, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = mne.read_source_estimate(fname_stc, subject='sample')
initial_time = 0.1
with use_3d_backend('mayavi'):
    brain = stc.plot(subjects_dir=subjects_dir, initial_time=initial_time,
                     clim=dict(kind='value', lims=[3, 6, 9]))
report = mne.Report()
report.add_figs_to_section(mlab.gcf(), 'caption')
I get:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/Documents/github_repos/mne-python/tutorials/source-modeling/plot_visualize_stc.py in <module>
     29 report = mne.Report()
     30 fig = mlab.gcf()
---> 31 report.add_figs_to_section(mlab.gcf(), 'caption')
     32 
     33 sfdfdfd
~/Documents/github_repos/mne-python/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,
~/Documents/github_repos/mne-python/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)
~/Documents/github_repos/mne-python/mne/viz/backends/_pyvista.py in _check_3d_figure(figure)
    845 def _check_3d_figure(figure):
    846     if not isinstance(figure, _Figure):
--> 847         raise TypeError('figure must be an instance of _Figure.')
    848 
    849 
TypeError: figure must be an instance of _Figure.
The error is very cryptic. If you do set_3d_backend at the beginning of the script, it works.
Also, having the figure handle easily accessible via brain.fig for both backends and then being able to pass that into the report will be a gamechanger.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (13 by maintainers)
 Top Results From Across the Web
Top Results From Across the Web
What's new — MNE 1.2.2 documentation
Fix bug with matplotlib-based 3D plotting where Axes3D were not properly initialized in mne.viz.plot_source_estimates() (#8811 by Chris ...
Read more >Shell 3D Visualization Center | School of Energy Resources
To foster new knowledge and insight, support interdisciplinary research, and drive integration between research computing, data science, visualization, ...
Read more >Arena3Dweb: interactive 3D visualization of multilayered ...
Efficient integration and visualization of heterogeneous biomedical information in a single view is a key challenge.
Read more > Top Related Medium Post
Top Related Medium Post
No results found
 Top Related StackOverflow Question
Top Related StackOverflow Question
No results found
 Troubleshoot Live Code
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free Top Related Reddit Thread
Top Related Reddit Thread
No results found
 Top Related Hackernoon Post
Top Related Hackernoon Post
No results found
 Top Related Tweet
Top Related Tweet
No results found
 Top Related Dev.to Post
Top Related Dev.to Post
No results found
 Top Related Hashnode Post
Top Related Hashnode Post
No results found

Okay let’s make this PyVista experience better rather than deal with Mayavi + PyVista mixing. @GuillaumeFavelier can you advise and update docs and maybe functions in a way that would have made things less painful for @jasmainak ?
Closing this as it should be taken care of as part of #9753