matlab
by lqx
三维图形绘制
plot3 函数
x = [0, 1, 2, 3];
y = [1, 2, 3, 4];
z = [2, 3, 4, 5];
plot3(x, y, z, 'r');
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Curve');
mesh 函数
[X, Y] = meshgrid(-2:0.2:2);
Z = X.^2 + Y.^2;
mesh(X, Y, Z);
colormap('jet');
alpha(0.5);% 设置透明度为0.5(半透明)
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Mesh');
等值线网格图
[x,y,z]=peaks(50);
subplot(131);mesh(x,y,z)
subplot(132);meshc(x,y,z)
subplot(133);meshz(x,y,z)
球体
[x,y,z]=sphere(15);%球
subplot(121);
mesh(x,y,z)
title('不透明球');
hidden off
subplot(122);
mesh(x,y,z)
title('透明球');
earthmap
surf 函数
%surf()表面着色,mesh()表面不着色
[x,y,z]=peaks(18);
subplot(131);surf(x,y,z),title('surf');
subplot(132);surfc(x,y,z),title('surfc');%surfc绘制了底层等高线
subplot(133);surfl(x,y,z),title('surfl');%surfl添加阳光
色彩
%meshgrid(0:0.1:5)
[X,Y] = meshgrid(-2:0.2:2) %距离切片;
Z = X.*exp(-X.^2-Y.^2);
surf(X,Y,Z);
colormap hsv %常用颜色分布
colorbar %颜色分布柱状图
拼图
[X,Y] = meshgrid(-2:0.2:2);
colormap hsv;
theta = 0:0.01:2*pi;
radi = abs(sin(2*theta).*cos(2*theta));
Height = randn(1000,1);
Weight = randn(1000,1);
subplot(2,2,1);surf(X.^2);title('1st');
subplot(2,2,2);surf(Y.^3);title('2nd');
subplot(2,2,3);polarplot(theta,radi);title('3rd');
subplot(2,2,4);scatter(Height,Weight);title('4th')
ight = randn(1000,1);
subplot(2,2,1);surf(X.^2);title(‘1st’);
subplot(2,2,2);surf(Y.^3);title(‘2nd’);
subplot(2,2,3);polarplot(theta,radi);title(‘3rd’);
subplot(2,2,4);scatter(Height,Weight);title(‘4th’)
``