用matlab
%读入聚类后的数据, 已经分好级别了,例如前4行是亚洲一流, %5-13是亚洲二流,14-24是亚洲三流 a=xlsread('C:\Users\Liugengxin\Desktop\1.xlsx','sheet3'); a1=a(1:4,:); a2=a(5:13,:); a3=a(14:24,:); %二维 % x1=a1(:,1);x2=a2(:,1);x3=a3(:,1); % y1=a1(:,2);y2=a2(:,2);y3=a3(:,2); % scatter(x1,y1,200,'.','r'); % hold on; % scatter(x2,y2,200,'.','g'); % hold on; % scatter(x3,y3,200,'.','b'); % % x1=a1(:,3);x2=a2(:,3);x3=a3(:,3); % y1=a1(:,4);y2=a2(:,4);y3=a3(:,4); % hold on; % scatter(x1,y1,200,'.','r'); % hold on; % scatter(x2,y2,200,'.','g'); % hold on; % scatter(x3,y3,200,'.','b'); % % x1=a1(:,5);x2=a2(:,5);x3=a3(:,5); % y1=a1(:,6);y2=a2(:,6);y3=a3(:,6); % hold on; % scatter(x1,y1,200,'.','r'); % hold on; % scatter(x2,y2,200,'.','g'); % hold on; % scatter(x3,y3,200,'.','b'); %三维 x1=a1(:,1);x2=a2(:,1);x3=a3(:,1); y1=a1(:,2);y2=a2(:,2);y3=a3(:,2); z1=a1(:,3);z2=a2(:,3);z3=a3(:,3); scatter3(x1,y1,z1,50,'x','b'); hold on; scatter3(x2,y2,z2,50,'x','g'); hold on; scatter3(x3,y3,z3,50,'x','m'); x1=a1(:,4);x2=a2(:,4);x3=a3(:,4); y1=a1(:,5);y2=a2(:,5);y3=a3(:,5); z1=a1(:,6);z2=a2(:,6);z3=a3(:,6); hold on; scatter3(x1,y1,z1,50,'x','b'); hold on; scatter3(x2,y2,z2,50,'x','g'); hold on; scatter3(x3,y3,z3,50,'x','m'); xlabel('pass'); ylabel('goal'); zlabel('score');
用python
import numpy as np import matplotlib.pyplot as plt import xlrd def xlrd_read_data(path): table = xlrd.open_workbook(path).sheets()[0] #读取第一个表格 row = table.nrows # 行数 col = table.ncols # 列数 datamatrix = np.zeros((row, col))#生成一个nrows行ncols列,且元素均为0的初始矩阵 for x in range(col): cols = np.matrix(table.col_values(x)) # 把list转换为矩阵进行矩阵操作 datamatrix[:, x] = cols # 按列把数据存进矩阵中 return datamatrix path = r'c:\Users\Liugengxin\Desktop\1.xlsx' data=xlrd_read_data(path) # x取第一列,y取第二列,z取第三列 x = data[:,0] y = data[:,1] z = data[:,2] ax = plt.subplot(111, projection='3d') # 创建一个三维的绘图工程 # 将数据点分成三部分画,在颜色上有区分度 # 0~4是一流数据 4~13是二流 13~24是三流 ax.scatter(x[:4], y[:4], z[:4], c='b',marker='x') # 绘制数据点 ax.scatter(x[4:13], y[4:13], z[4:13], c='g',marker='x') ax.scatter(x[13:24], y[13:24], z[13:24], c='m',marker='x') ax.set_zlabel('pass') # 坐标轴 ax.set_ylabel('goal') ax.set_xlabel('score') plt.show()
结果
python matlab