创建三维绘图
以下示例演示如何在 MATLAB® 中创建各种三维绘图。
网格图
mesh
函数可创建线框网格图。默认情况下,网格图颜色与曲面高度成正比。
z = peaks(25); figure mesh(z)
曲面图
surf
函数用于创建三维曲面图。
surf(z)
曲面图(着色)
surfl
函数使用基于颜色图的光照创建曲面图。为了实现更平滑的颜色过渡,请使用具有线性强度变化的颜色图,如 pink
。
surfl(z) colormap(pink) % change color map shading interp % interpolate colors across lines and faces
等高线图
contour
函数用于创建包含常量值等高线的绘图。
contour(z,16) colormap default % change color map
二维箭头图
quiver
函数将二维向量绘制为箭头。
x = -2:.2:2;
y = -1:.2:1;
[xx,yy] = meshgrid(x,y);
zz = xx.*exp(-xx.^2-yy.^2);
[px,py] = gradient(zz,.2,.2);
quiver(x,y,px,py)
xlim([-2.5 2.5]) % set limits of x axis
三维体的切片图
slice
函数显示三维体数据的切片平面的数据。
x = -2:.2:2; y = -2:.25:2; z = -2:.16:2; [x,y,z] = meshgrid(x,y,z); v = x.*exp(-x.^2-y.^2-z.^2); xslice = [-1.2,.8,2]; % location of y-z planes yslice = 2; % location of x-z plane zslice = [-2,0]; % location of x-y planes slice(x,y,z,v,xslice,yslice,zslice) xlabel('x') ylabel('y') zlabel('z')