pyvistaqt 3d backend - plot not interactive

  • MNE version: e.g. 1.1.0
  • pyvista version: e.g. 0.36.1
  • pyvistaqt version: e.g. 0.9.0
  • operating system: e.g. macOS 10.15

Hello,

I encountered an issue while trying to plot source localization.
Here is a snippet of the code I’m using.

import os
import mne
from mne import read_source_estimate
from mne.datasets import sample
print(__doc__)

# Paths to example data
sample_dir_raw = sample.data_path()
sample_dir = os.path.join(sample_dir_raw, 'MEG', 'sample')
subjects_dir = os.path.join(sample_dir_raw, 'subjects')
fname_stc = os.path.join(sample_dir, 'sample_audvis-meg')
stc = read_source_estimate(fname_stc, subject='sample')

# Define plotting parameters
surfer_kwargs = dict(
    hemi='lh', subjects_dir=subjects_dir,
    clim=dict(kind='value', lims=[8, 12, 15]), views='lateral',
    initial_time=0.09, time_unit='s', size=(800, 800),
    smoothing_steps=5)

# Plot surface
with mne.viz.use_3d_backend('pyvista'):
    brain=stc.plot(**surfer_kwargs, time_viewer=True)
brain.add_text(0.1, 0.9, 'SourceEstimate', 'title', font_size=16)

The pyvistaqt window does appear without any error, but I can’t interact with it, the Mac Spinning Wheel appearing.
Do you have any idea?

Hello @aalt, and welcome to the forum!

How did you run the code you shared with us? From the terminal, from a Juypyter Notebook, from the VS Code interactive window, …?

Also, could you please share the output of

import mne
mne.sys_info()

Thanks!

Richard

Dear @richard, thank you!
I am using PyCharm environment.

mne.sys_info() gives:

Platform:         macOS-10.15.7-x86_64-i386-64bit
Python:           3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]
Executable:       /Users/anaelle/PycharmProjects/main/venv/bin/python
CPU:              i386: 4 cores
Memory:           Unavailable (requires "psutil" package)
mne:              1.1.0
numpy:            1.23.1 {}
scipy:            1.9.0
matplotlib:       3.5.2 {backend=MacOSX}
sklearn:          1.1.1
numba:            Not found
nibabel:          4.0.1
nilearn:          0.9.1
dipy:             Not found
cupy:             Not found
pandas:           1.4.3
pyvista:          0.36.1 {OpenGL 4.1 NVIDIA-14.0.32 355.11.11.10.10.143 via NVIDIA GeForce GT 755M OpenGL Engine}
pyvistaqt:        0.9.0
ipyvtklink:       Not found
vtk:              9.2.0.rc2
qtpy:             2.1.0 {PyQt5=5.15.2}
ipympl:           Not found
pyqtgraph:        Not found
pooch:            v1.6.0
mne_bids:         Not found
mne_nirs:         Not found
mne_features:     Not found
mne_qt_browser:   Not found
mne_connectivity: 0.3
mne_icalabel:     0.2

Bests.

Thank you.

  • Can you try to run the script from the command line, outside of PyCharm, to see if this changes anything?
  • Getting MNE and all dependencies installed manually in a way that actually works well can be notoriously difficult. We therefore suggest you closely follow our installation instructions, which ask you to create a conda environment; or you could even try out our standalone installer if you want.

Best wishes,
Richard

Dear @richard, running the script in the terminal directly in Python has worked perfectly.
Also running it in the terminal through PyCharm works fine.
Looks like only the Python Console from PyCharm gives rise to this issue.

Thank you !

So after testing a few things up, like changing backends in source files, using several functions for plotting and visualisation, it turned out adding matplotlib.use('Qt5Agg') solved the problem !
While I thought it was using default Qt5Agg backend, apparently it was not and forcing it did the thing.

Bests.