When 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.
When I do the following:
I get:
The error is very cryptic. If you do
set_3d_backendat the beginning of the script, it works.Also, having the figure handle easily accessible via
brain.figfor both backends and then being able to pass that into the report will be a gamechanger.