Why does using a different IDE affect my raw.plot()?

I’m using MNE .22 with Python 3.9.2 on a Mac running OS 10.15.4. I switched from Matlab to Python a couple years ago and have been using Idle as my IDE up to now, but have to decided to transition to PyCharm. I’ve discovered something peculiar when creating a plot of my raw data:

import mne as mn
import matplotlib.pyplot as plt
raw = mn.io.read_raw_edf("my_file.edf", preload=True)

It couldn’t be any simpler. :grinning:This works fine when I run it from the shell in Idle and I’m able to scroll through my data. In PyCharm, I get the data plot, but it closes immediately. No chance to scroll, remove bad channels, or annotate.

Python 3.9 (ProjectName) -/PyCharmProjects/ProjectName/venv/bin/python

is the listed interpreter, although I understand little about venv and virtual environments.

I should mention that many plot tools I’ve created using Matplotlib, which utilize MNE for loading data, extracting raw.info, etc. work fine. when I run them from PyCharm.

I apologize if this question isn’t really appropriate for this forum. Also, if any MNE users have a preferred IDE, I’d enjoy hearing suggestions.


The Python interpreter closes immediately after opening the plot window, because the end of your script is reached. You have two ways to work around this:

  • Ensure execution is halted after plotting by passing block=True, i.e. raw.plot(block=True)
  • Or edit your PyCharm run configuration such that your script is run in interactive mode (which might be something you want when working with data interactively anyway!) by ticking the “Run with Python Console” box. See Create and edit run/debug configurations—PyCharm for more info on run configurations in PyCharm

To answer your question about IDEs, we have a brief discussion here that tries not to be too opinionated: Installing MNE-Python — MNE 0.23.dev0 documentation

Personally I started out on Spyder, then switched to Atom after a couple years, and a couple years later switched to VSCode. Several other MNE-Python devs also use VSCode, some use PyCharm, at least one was using emacs (as of 2019 at least). A lot of the folks in my research institute (MNE-Python users, not devs) prefer Spyder (which is much better nowadays than it was when I stopped using it).


4 posts were split to a new topic: Problems running mne.viz.plot_alignment() from within Spyder

A post was split to a new topic: MNE objects not shown in Spyder variable explorer