我想绘制完整记录的脑电图信号以进行快速目视检查或查看例如过滤。
当将原始数据作为 Pandas DataFrame 读取时,我可以轻松地绘制它并得到这样的图表(单通道):
eeg['Pz'].plot()
但是,一旦导入到 MNE,绘图功能总是会向我显示事件/纪元,如下所示:
raw.plot(picks="Pz")
有没有办法:
有一种方法可以访问原始数据并使用 matplotlib 绘制它。请参阅下面的代码片段:
import matplotlib.pyplot as plt
eeg = raw.get_data() # with no other parameters, returns a ch x samples 2D ndarray https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.get_data
channels = {}
for ch, i in enumerate(raw.ch_names):
channels[ch] = i
# above snippet creates a dictionary that maps channel names to row indices, that way you can use a channel name to view a specific channel's data in the ndarray
plt.plot(eeg[channels["Pz"]]) # plots data over samples rather than time
绘制随时间变化的数据:
time_data = np.arange(0, len(eeg[channels["Pz"]]), 1/500) # you would need to replace the 500 with your sampling rate
plt.plot(time_data, eeg[channels["Pz"]])