I cannot plot anything with mne in visual studio

I was trying MNE tutorial’s decoding section on a data and the plots that are supposed to be shown are not being shown. One or two windows closes instantly for csp.plot code lines and, for epochs.plot() a MNE window opens but in a way that it does not respond (MNE visualization app uses 5-6 GB of RAM, this is way it probably does not respond). What can be the problem? What can I do to see these plots? The info and the code is given below.

  • MNE version: 1.0.3
  • operating system: Windows 10
from winreg import QueryInfoKey
import numpy as np
import matplotlib.pyplot as plt

import matplotlib 
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression

import mne
from mne.datasets import sample
from mne.decoding import (SlidingEstimator, GeneralizingEstimator, Scaler,
                          cross_val_multiscore, LinearModel, get_coef,
                          Vectorizer, CSP)
data_file = 's22_epochs_autoreject-epo.fif'
epochs = mne.read_epochs(data_file)
epochs.plot()
X = epochs.get_data()  # MEG signals: n_epochs, n_meg_channels, n_times
y = epochs.metadata.Congruency

csp = CSP(n_components=3, norm_trace=False)
clf_csp = make_pipeline(
    csp,
    LinearModel(LogisticRegression(solver='liblinear'))
)
scores = cross_val_multiscore(clf_csp, X, y, cv=5, n_jobs=1)
print('CSP: %0.1f%%' % (100 * scores.mean(),))

# Fit CSP on full data and plot
csp.fit(X, y)
csp.plot_patterns(epochs.info)
csp.plot_filters(epochs.info, scalings=1e-9)

Hello @jubar, and welcome to the forum!

How do you run your script from VS Code?

Could you please share the output of

import mne
mne.sys_info()

Thanks!

Richard

I added plt.show() to the end and it solved my problem. The output is given below, after this error the code works anyway.

conda activate 1.1.0_0
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or  
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda activate 1.1.0_0
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Platform:         Windows-10-10.0.19044-SP0
Python:           3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 06:57:19) [MSC v.1929 64 bit (AMD64)]
Executable:       \...\...\mne-python\1.1.0_0\python.exe
CPU:              Intel64 Family 6 Model 165 Stepping 2, GenuineIntel: 12 cores
Memory:           15.9 GB

mne:              1.1.0
numpy:            1.21.6 {blas=NO_ATLAS_INFO, lapack=lapack}
scipy:            1.9.0
matplotlib:       3.5.2 {backend=QtAgg}

sklearn:          1.1.1
numba:            0.55.2
nibabel:          4.0.1
nilearn:          0.9.1
dipy:             1.5.0
cupy:             Not found
pandas:           1.4.3
pyvista:          0.36.1 {OpenGL 4.5.0 - Build 27.20.100.8476 via Intel(R) UHD Graphics}
pyvistaqt:        0.9.0
ipyvtklink:       0.2.2
vtk:              9.1.0
qtpy:             2.1.0 {PyQt5=5.15.4}
ipympl:           0.9.1
pyqtgraph:        0.12.4
pooch:            v1.6.0

mne_bids:         0.10
mne_nirs:         0.2.1
mne_features:     0.2
mne_qt_browser:   0.3.1
mne_connectivity: 0.3
mne_icalabel:     Not found

Thank you for your attention.

1 Like

I believe you need to run conda init powershell to make this message go away.

Where should I run conda init powershell? In Pycharm it says that I should run it in anaconda prompt but I cannot find anaconda promt, How can I open it?

How did you install MNE?

From MNE’s website (there is a guide to download MNE). I followed the instructions.

yes, but… Installing MNE-Python — MNE 1.1.0 documentation has several different approaches: a standalone installer, using pip, using conda, installing with/without hdf5 support… can you be more specific?