Images cannot be displayed using the ploy raw() function

Dear all,
I had a problem when I used the plot_raw() function in MNE. When I ran the code, Pycharm showed a drawing window that disappeared immediately, and then I debug it with a breakpoint in front of the plot_raw() line. The drawing window appeared but not every time it was successfully displayed. The solution I found on the Internet was to change the backend parameter of matplotlib to TkAgg, but I found that my computer’s default parameter is TkAgg, and I can use the plot function to draw other patterns, such as line charts, bar charts, and so on.
Thanks!

Hello, please share the output of

import mne 
mne.sys_info()

and a minimal example of the code that reproduces your problem.

Thanks!
Richard

The code:

import matplotlib as mpl
import matplotlib.rcsetup as rcsetup
#mpl.use('TkAgg')
import matplotlib.pyplot as plt
import mne

directory=('sub-PD0016_ses-01_task-rest_run-01_meg.ds')
raw=mne.io.read_raw_ctf(directory, system_clock='truncate', preload=False, clean_names=False, verbose=None)
#raw.plot()
mne.viz.plot_raw(raw, events=None, duration=10.0, start=0.0, n_channels=20, bgcolor='w', color=None, bad_color='lightgray', event_color='cyan', scalings=None, remove_dc=True, order=None, show_options=False, title=None, show=True, block=False, highpass=None, lowpass=None, filtorder=4, clipping=1.5, show_first_samp=False, proj=True, group_by='type', butterfly=False, decim='auto', noise_cov=None, event_id=None, show_scrollbars=True, show_scalebars=True, time_format='float', precompute=None, use_opengl=None, theme=None, overview_mode=None, verbose=None)

The sys_info:
Platform: Windows-10-10.0.19041-SP0
Python: 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)]
Executable: F:\aa\test\Scripts\python.exe
CPU: Intel64 Family 6 Model 142 Stepping 11, GenuineIntel: 8 cores
Memory: 7.8 GB

mne: 1.1.1
numpy: 1.23.3 {}
scipy: 1.9.1
matplotlib: 3.6.0 {backend=TkAgg}

sklearn: Not found
numba: Not found
nibabel: Not found
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: Not found
pyvista: 0.37.0 {OpenGL 4.5.0 - Build 30.0.101.1692 via Intel(R) UHD Graphics 620}
pyvistaqt: 0.9.0
ipyvtklink: Not found
vtk: 9.2.2
qtpy: Not found
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: Not found
mne_icalabel: Not found

what happens when you do this?

import mne

directory = 'sub-PD0016_ses-01_task-rest_run-01_meg.ds'
raw = mne.io.read_raw_ctf(directory, system_clock='truncate', preload=False,
                          clean_names=False, verbose=None)
raw.plot()

does that work?

It pops up the Figure window, but it disappears immediately before the content appears

I’d suggest to install mne-qt-browser, our new and enhanced plotting user interface. And you will probably need to pass block=True to the plotting function as well, depending on how you run your script (otherwise the figure might close immediately once the end of the script is reached)

Best wishes,
Richard

When I pass block=True, it displays successfully!
Thanks a lot! :smiley: