Creating 3-D Plots
This example shows how to create a variety of 3-D plots in MATLAB®.
Open Live Script
Mesh Plot
‘The mesh function creates a wireframe mesh. By default, the color of the mesh is proportional to the surface height,
2 = peaks(25);
figure
mesh(z)
A
LN WRT
* WO
= LY
z
25
Surface Plot
‘The surf function is used to create a 3-D surface plot.
surf(z)
colormap(jet) % change color map10
“10
25
Surface Plot (with Shading)
‘The sur function creates a surface plot with colormap-based lighting. For smoother color transitions, use a colormap with linear
intensity variation such as pink.
surfl(z)
colormap(pink) — % change color map
shading interp % interpolate colors across lines and faces
10
“10
25
Contour Plot‘The contour function is used to create a plot with contour lines of constant value.
contour(z,16)
colormap default — % change color map
5
10
Quiver Plot
‘The quiver function plots 2-D vectors as arrows.
x = 21.2125
ye -l2s
Locyy] = meshgrid(x,y)5
22 = xx. *exp(-XXx.2-Yy-*2)5
[px,py] = gradient(zz,.2,.2);
quiver (x,y, Px, Py)
xLim([-2.5 2,5])% set Limits of x axis