Python launcher opens and immediately closes matplotlib.

The answer @richard linked to may be a bit confusing since it’s not clear that you’re using PyCharm (as that asker was). The gist of the answer is the same though: Python can run in two ways: interactive and non-interactive mode. From the command line, this is controlled by the -i flag:

$ python myscript.py     # non-interactive
$ python -i myscript.py  # interactive

in interactive mode, when the end of the script is reached, the python interpreter stays open and lets you enter additional commands. A side-effect of this is that any plots that your script opened will also stay open.

If you’re running your script through an IDE, it might automatically use interactive mode, or you may need to look around in the commands / settings for a way to tell it which mode to use when running scripts.

As mentioned in the linked answer, another option is using the MNE-Python plotting function option block=True, which pauses script execution while that plot is open, and continues with the script only after you manually close the plot. However, not all plotting functions have this option (raw.plot_psd() does not; raw.plot() does) so it won’t always be enough.