Extract values from the 'plot_psd' method

  • MNE version: 0.24.1
  • operating system: Windows 10

Hello!
How can I extract the values from the raw.plot_psd figure? I’ve seen others rasing the similar question and the answer is to use the psd_welch method to calculate it manually.
However I am really poor at the basic knowledges so I cannot fully understand the parameters of the method. Here is the code I tried my best with:

raw.plot_psd(fmin=0,fmax=100)
psds,freqs=mne.time_frequency.psd_welch(raw,fmin=0,fmax=100)
plt.plot(psds[0], linewidth=0.25)
plt.show()

The output of the two figures are completely different, and I don’t know how to get the data as ndarray from plot_psd figure. Can anyone help me to correct the code? Thanks very much!

fig1:plot_psd

fig2:psd_welch
fig2

I might be mistaken, but I believe the difference comes from the Y-axis units. When using .plot_psd(), one of the arguments is dB to plot in (amplitude**2/Hz (dB)), while mne.time_frequency.psd_welch returns data in plain (amplitude**2/Hz) (I think, I actually never paid attention to this).

A second difference is in the argument n_fft which does not have the same default in both functions.