Problem in using raw.plot() under terminal

Dear all,
I have a simple mne script, named with data_check.py, to plot and browse through the raw MEG/EEG data. The script contains these lines:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import mne
raw = mne.io.read_raw_fif('file_name.fif', preload=True)
raw.plot()

When running the code in Spyder IDE, it works perfectly fine and I can browse through the plot. But when running the same script directly in terminal as:

$ python data_check.py

The plots initiates but closes within a second automaticaly with a message Using qt as 2D backend.

I also tried it as:

$ python -c "import mne; raw = mne.io.read_raw_fif('file_name.fif', preload=True); raw.plot()"

But it also initiates and closes within a second automaticaly with the same message.

  • MNE version: 1.5.1
  • operating system: Ubuntu 20.04.6 LTS (64 bit)

Could someone help me, how to resolve it.
Thanks a lot.

raw.plot is non-blocking by default. Thus, if you run this code snippet in an non-interactive python session (spyder console is interactive), then it will execute the code snippet and exit when it runs out of lines to execute.

If you want to make it blocking, you can use raw.plot(block=True). From the block argument docstring:

Whether to halt program execution until the figure is closed.

Mathieu

3 Likes

That’s cool, I did not realize that there is a block parameter! I think running the script in interactive mode should work as well, i.e.

python -i data_check.py
2 Likes

Thanks @mscheltienne .
It worked after using block=True

1 Like