出图结果如下:
代码如下,按需修改
clear;clc;
numRows=100; %数据区域,步长,步数
numCols=100;
ax=-2;bx=2;
ay=-2;by=2;
hx=(bx-ax)/numCols;
hy=(by-ay)/numRows;
XXC=ax:hx:bx; %坐标阵,data
YYC=ay:hy:by;
CCC=zeros(numRows+1,numCols+1);
hold off;
for ix=1:numCols %绘云图用的数据data
for iy=1:numRows
x=XXC(1,ix);
y=YYC(1,iy);
CCC(iy,ix)=x*exp(-(y*y+x*x));
end
end
nhang=4; %划分区域4行五列 跟据自己的需要更改
nlie=5;
wei_shu=3;
figure(1)
%contour(XXC,YYC,CCC,[0 1])
[C,h]=contourf(XXC,YYC,CCC,10); %等高线云图 10条等高线 可修改等高线数量
clabel(C,h)
colorbar
colormap(parula)
%parula 还可修改为不同的colormap: jet hsv hot cool spring summer autumn
%winter gray bone copper pink lines colorcube prism flag white
hold on
wei_shu1=strcat('%.',num2str(wei_shu),'f');
Hx=(bx-ax)/nlie;
Hy=(by-ay)/nhang;
X_domain=ax:Hx:bx; %分区域的坐标
Y_domain=ay:Hy:by;
for iy=1:nhang+1
x_points=[ax,bx];
y_points=[Y_domain(1,iy),Y_domain(1,iy)];
plot(x_points,y_points,'k-');
end
for ix=1:nlie+1
x_points=[X_domain(1,ix),X_domain(1,ix)];
y_points=[ay,by];
plot(x_points,y_points,'k-');
end
axis equal;
xlim([min(XXC)-0.5 max(XXC)+0.5]);
ylim([min(YYC)-0.5 max(YYC)+0.5]);
axis off;
C_average=mean(mean(CCC,1),2);
C_AVERAGE=num2str(C_average);
% pcolor(X,Y,C);
% shading flat;
% color bar;
% grid on;
NNNNn=strcat('平均值',C_AVERAGE);
hold off;
text(ax,ay*10/9,NNNNn);
% ylabel('Row');
title('划分区域的等高线云图')