Overlapping multiple PSDs in on figure

  • MNE version: 0.24.0
  • operating system: macOS 14

Hi! I have plotted multiple individual PSDs from EEG data using the following code:

raw_PD_6 = mne.io.read_raw_fif ('/Users/cinthia/UO/Coding/PD_offmeds/PD_06_off_rest_S1_V1_ica_raw.fif', preload=True) 
PD_6_psd_alpha1=raw_PD_6.compute_psd(method='welch', fmin=10, fmax=13, tmin=1, tmax=100, picks=['F4' ])

PD_6_psd_alpha1.plot()

Still, I want to know if I can do this with multiple channels at the time because whenever I try to change picks=['F4' ] to picks=['all ], I get an error.

Besides, I want to plot all my PSDs into one figure without averaging them. I want to see how they overlap one on top of each other all in one figure so people can better visualize how they differ.

Are both of these things possible?

If you don’t specify picks at all (that is, use the default of picks=None), PSDs for all (good) channels will be computed. You can then plot the computed PSDs, and by default you should see individual PSDs, i.e. raw.compute_psd().plot() should do what you want.

Hi, thank you for the help. picks=None worked well but once I try to plot it I get this error: AttributeError: 'NoneType' object has no attribute '_get_renderer'

Any idea on how to fix it?

This is the full code in case it is useful:

raw = mne.io.read_raw_fif ('/Users/cinthia/UO/Coding/PD_offmeds/PD_05_off_rest_S1_V1_ica_raw.fif', preload=True) 
raw_psd=raw.compute_psd(method='welch', fmin=3, fmax=70, tmin=1, tmax=100, picks=None)

raw_psd.plot()

Just to make sure, does this statement also result in the same error?

raw.compute_psd().plot()

I was able to fix it. I had the same problem as here: Jupyter yields: 'NoneType' object has no attribute '_get_renderer' · Issue #11799 · mne-tools/mne-python · GitHub. I add it in case someone else is experiencing the same thing. Thank you Clemens for the code. I was later then able to use it without error.

1 Like

I missed that you were using MNE 0.24, which is really really old. You should always use the latest version (1.7 currently) if possible!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.