Matlab关于画数据网格图

1、surf(Z);

Z为一个矩阵,如果Z是向量,那么就需要先将其转换为矩阵

reshape(Z,[length(X),length(Y)]);  X和Y为你的横坐标取值个数。

具体代码调用格式如下

Z=reshape(acc,[length(lambda2),length(lambda1)]);
surf(Z);
xlabel('\alpha','fontsize',20);
set(gca, 'xtick',1:2:11);
set(gca,'xticklabel',{'10^-5','10^-3','10^-1','10^1','10^3','10^5'})
ylabel('\beta','fontsize',20);
set(gca, 'ytick',1:2:11);
set(gca,'yticklabel',{'10^-5','10^-3','10^-1','10^1','10^3','10^5'});
zlabel('Classification accuracy (%)','fontsize',20);
colorbar('fontsize',12);
 view(135,55); title('AR','fontsize',20); print('-depsc','AR_4.eps');

 2、matlab plotyy 一条横轴,两条纵轴

clear all
clc
figure;
COIL20_convergence_Acc = xlsread(‘收敛曲线.xls');
obj = COIL20_convergence_Acc(:,1)';
eachacc = COIL20_convergence_Acc(:,2)';
x = 1:size(obj,2);
[AX,H1,H2] = plotyy(x,obj,x,eachacc,'plot');
legend('Objective function value','Classification accuracy');
set(gca,'fontsize',14);  
% set(get(AX(1),'Xlabel'),'String','Number of iterations');
set(get(AX(1),'Ylabel'),'String','Objective function value','fontsize',14,'color','k');
set(get(AX(2),'Ylabel'),'String','Classification accuracy','fontsize',14,'color','k');
xlabel('Number of iterations');
set(get(gca,'xlabel'),'fontsize',14);                    % 设置标尺字体大小
set(H1,'marker','.'); 
set(H2,'marker','.'); 

3、scatter3, 画散点图

对于一个n_sample*dim_fea的数据(1000*3维数据)

调用格式为:scatter3(X(:,1),X(:,2),X(:,3),'b','o','filled');    % 其中b为颜色,o为用圆圈标记,filled表示实心

scatter(x,y,a,c)  : a为区域尺寸, c为数据点颜色(向量)。

scatter(LPP_data(:,1),LPP_data(:,2),12,1:1:1000,'+');

PCA LPP NPE对于随机散点图降维显示结果如下: 部分降维代码见:http://lvdmaaten.github.io/drtoolbox/#download

% 散点图 降维学习
clear all
clc
addpath('G:\机器学习\代码和数据集\代码\降维\drtoolbox\techniques\');
% load twinpeaks;
[X, labels, t] = generate_data('twinpeaks',1000);   % swiss
% load swiss
figure;
scatter3(X(:,1),X(:,2),X(:,3),12,1:1:1000,'o'); title('original twinpeaks');

% PCA
options.ReducedDim = 2;
[eigvector, eigvalue, meanData, PCA_data] = PCA(X, options);
figure;
scatter(PCA_data(:,1),PCA_data(:,2),12,1:1:1000,'o'); title('PCA twinpeaks');

% [mappedX, mapping] = pca(X, 2);

% NPE
no_dims = 2;
k = 10;
[NPE_data, mapping] = npe(X, no_dims, k);
figure;
scatter(NPE_data(:,1),NPE_data(:,2),12,1:1:1000,'o'); title('NPE twinpeaks');

% LPP
[LPP_data, mapping] = lpp(X, no_dims, k);
figure;
% scatter(LPP_data(:,1),LPP_data(:,2),12,'b','.'); title('LPP twinpeaks');
% figure;
scatter(LPP_data(:,1),LPP_data(:,2),12,1:1:1000,'o'); title('LPP twinpeaks');

  

4、生成颜色矩阵 colour = hsv(num)

5、按照类标来显示散度图

% 散点图 降维学习
clear all
clc
addpath('G:\机器学习\代码和数据集\代码\降维\drtoolbox\techniques\');
% load twinpeaks;
[X, labels, t] = generate_data('twinpeaks',1000);   % swiss
% load swiss
figure;
indx = find(labels == -1);
scatter3(X(indx,1),X(indx,2),X(indx,3),12,'b','o'); 
hold on 
indx1 = find(labels == 0);
scatter3(X(indx1,1),X(indx1,2),X(indx1,3),12,'k','o'); title('original twinpeaks');


% PCA
options.ReducedDim = 2;
[eigvector, eigvalue, meanData, PCA_data] = PCA(X, options);
figure;
scatter(PCA_data(indx,1),PCA_data(indx,2),12,'b','o');
hold on 
scatter(PCA_data(indx1,1),PCA_data(indx1,2),12,'k','o'); 
title('PCA twinpeaks');

% [mappedX, mapping] = pca(X, 2);

% NPE
no_dims = 2;
k = 10;
[NPE_data, mapping] = npe(X, no_dims, k);
figure;
scatter(NPE_data(indx,1),NPE_data(indx,2),12,'b','o');
hold on 
scatter(NPE_data(indx1,1),NPE_data(indx1,2),12,'k','o');
title('NPE twinpeaks');

% LPP
[LPP_data, mapping] = lpp(X, no_dims, k);
figure;
% scatter(LPP_data(:,1),LPP_data(:,2),12,'b','.'); title('LPP twinpeaks');
% figure;
scatter(LPP_data(indx,1),LPP_data(indx,2),12,'b','o'); 
hold on 
scatter(LPP_data(indx1,1),LPP_data(indx1,2),12,'k','o'); 
title('LPP twinpeaks');

  

6

 

 

未完待续

转载于:https://www.cnblogs.com/Jerry-PR/p/5035104.html

你可能感兴趣的:(Matlab关于画数据网格图)