[英]How to set x-axis labels on a figure plotted using matplotlib's pyplot?
[英]Pyplot - How to set labels to multiple data plotted in the same subplot ax
我有一个包含多类数据的数据集。 它们的组织方式如下:[渠道,示例,任务]。 有5个通道,每个任务每个通道1024个样本,并且有270个任务。 我要5个地块。 每个频道一个。 我想标记每个通道中的每个任务。 我只有颜色可以及时识别每个任务。 但是颜色与任务无关。
import scipy.io as sio
import numpy as np
import matplotlib.pyplot as plt
mat_contents = sio.loadmat('SubA_5chan_3LRF')
info = mat_contents['Info']
labels = mat_contents['LABELS']
eegdata = mat_contents['EEGDATA'] # [channels, sample in time, trial]
tam_janela = len(eegdata[0, :, 0])
fig, (ch1, ch2, ch3, ch4, ch5) = plt.subplots(nrows = 5, ncols = 1, sharex = False, sharey=True)
for trial in range(10):
x = np.linspace(0, (tam_janela + tam_janela*trial), (tam_janela + tam_janela*trial) )
ch1.plot((x[(trial*1024):]), eegdata[0, :, trial])
ch1.set_ylabel('Channel 1 (V)')
ch2.plot((x[(trial*1024):]), eegdata[1, :, trial])
ch2.set_ylabel('Channel 2 (V)')
ch3.plot((x[(trial*1024):]), eegdata[2, :, trial])
ch3.set_ylabel('Channel 3 (V)')
ch4.plot((x[(trial*1024):]), eegdata[3, :, trial])
ch4.set_ylabel('Channel 4 (V)')
ch5.plot((x[(trial*1024):]), eegdata[4, :, trial])
ch5.set_xlabel('Time')
ch5.set_ylabel('Channel 5 (V)')
plt.suptitle('EEG recordings from Subject A with 5 channels')
plt.show()
for trial in range(12):
x = np.linspace(0, (tam_janela + tam_janela*trial), (tam_janela + tam_janela*trial) )
if labels[trial] == 1:
task_label = 'Left Hand'
elif labels[trial] == 2:
task_label = 'Right Hand'
elif labels[trial] == 3:
task_label = 'Both feet'
lab, = ch1.plot((x[(trial*1024):]), eegdata[0, :, trial], label = 'Inline label')
ch1.set_ylabel('Channel 1')
lab.set_label(task_label)
ch2.plot((x[(trial*1024):]), eegdata[1, :, trial])
ch2.set_ylabel('Channel 2')
ch3.plot((x[(trial*1024):]), eegdata[2, :, trial])
ch3.set_ylabel('Channel 3')
ch4.plot((x[(trial*1024):]), eegdata[3, :, trial])
ch4.set_ylabel('Channel 4')
ch5.plot((x[(trial*1024):]), eegdata[4, :, trial])
ch5.set_xlabel('Time')
ch5.set_ylabel('Channel 5')
ch1.legend(loc='center left', fontsize = 7, ncol = 12)
plt.suptitle('EEG recordings from Subject A with 5 channels (V)')
plt.grid(True)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.