二维图示
import matplotlib.pyplot as plt
from scipy.io import loadmat
alldata = loadmat('E:\BCI\physionet\mat\s1data\Model_csp3_1\model2\model2_3\Real_fea.mat')
data=alldata['feature_L_R']
ax = plt.subplot()
ax.set_title("Input data")
# Plot the training points
ax.scatter(data[0:35, 0],data[0:35, 1] , c='r',label='left',
edgecolors='k')#向左想象的特征向量选择两维
ax.scatter(data[35:70, 0],data[35:70, 1] , c='g',label='right',
edgecolors='k')#向右想象的特征向量选择两维
plt.legend(loc='upper right')#图标显示在图的右上角
plt.show()
第二种画法:
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
cm = plt.cm.RdBu
cm_bright = ListedColormap(['#FF0000', '#0000FF'])
ax = plt.subplot(len(datasets), len(classifiers) + 1, i)
ax.scatter(X_train[:, 0], X_train[:, 1], c=y_train, cmap=cm_bright,
edgecolors='k')
# and testing points
ax.scatter(X_test[:, 0], X_test[:, 1], c=y_test, cmap=cm_bright, alpha=0.6,
edgecolors='k')
plt.show()
代码说明:
cm_bright:表示绘制两个颜色
X_train:数据格式为100*2的二维数组,是100个特征,每个特征又两个特征值,对应散点图的x和y。相对应的y_train为100的一维数组,其值为0或1,代表训练的100个数据的类别,为0的在散点图中为一种颜色,为1的在散点图中为另一种颜色。
测试数据的格式同上。
三维图示
import matplotlib.pyplot as plt
from scipy.io import loadmat
alldata = loadmat('E:\BCI\physionet\mat\s1data\Model_csp3_1\model2\model2_3\Real_fea.mat')
data=alldata['feature_L_R']
for i in range(34):
ax = plt.subplot(111, projection='3d') # 创建一个三维的绘图工程
#将数据点分成三部分画,在颜色上有区分度
ax.scatter(data[0:35,i],data[0:35,i+1],data[0:35,i+2],c='r') #绘制数据点
ax.scatter(data[35:70,i],data[35:70,i+1],data[35:70,i+2],c='g')
ax.set_zlabel('Z') #坐标轴
ax.set_ylabel('Y')
ax.set_xlabel('X')
plt.show()
说明:data数据为35*36,