3D Plots in MATLAB - GeeksforGeeks

09 May, 2021
In MATLAB, we can plot different types of modules like 2d plotting and 3d plotting. In this article, we will see what are the various types of 3D plotting.
Mesh Plot: A mesh plot is a 3d surface that creates different types of meshes for different types of expression. To create mesh we have to give the values x and y for z, (z= f(x, y)). For plotting the mesh plot it has mesh() which will generate the 3d surface. It has solid edge color but no face color.
Syntax:
mesh(Z)
Example:
Matlab
% give the input of x and y.[x,y]= meshgrid(0:0.1:5);  % give the expression for x % and y for the output in zz= sin(x).*cos(y);  % mesh() is used for 3D plottingmesh(z);
Output:
Surface plot: A surface plot is a 3d surface that creates different types of surfaces for different expressions. To create a surface we have to give the values x and y for z, (z= f(x, y)). For plotting the surface plot it has surf() which will generate the 3d surface. It has solid edge color and solid face color
Syntax:
surf(Z)
Example:
Matlab
% give the input for x and y[x,y]= meshgrid(0:0.1:5);  % give the expression for % x and y for the value of z.z= sin(x).*cos(y);  % use surf() for the plotting surf(z)
Output:
Surface plot(with shading): A surface plot that creates a three-dimensional surface plot that has solid edge colors and solid face colors and also has shading. In surface with shading, we have to give the values x and y for z, (z= f(x, y)).  For plotting the surface plot it has surf(z) is used for 3d plotting.
Syntax:
surfl(z)
There are three types of shading available:
shading flatshading facetedshading interp
shading flat
shading faceted
shading interp
Example:
Matlab
% give the input for x and y[x,y]= meshgrid(0:0.1:5);  % give the expression for x and y % for the value of zz= sin(x).*cos(y);  % use surfl() for the plotting % shading faceted is by defaultsurfl(z)shading facetedtitle('Faceted Shading')  % use shading flat for each mesh% line segment and face has a % constant color surfl(z)shading flattitle('Flat Shading')  % use shading flat for varies the % color in each line segment and % face by interpolatingsurfl(z)shading interptitle('Interpolated Shading')
Output:
Contour plot: A contour plot is also called a line plot. To plot contour it has x, y variables which are used to give the values for z, (z=f(x, y)). The x and y variables are usually in a grid called meshgrid.
Syntax:
contour(Z)
Example:
Matlab
% enter the inputs of x and y[x,y]= meshgrid(0:0.1:5);  % enter the expression using% x and y z= sin(x).*cos(y);  % use contour() for plotting contour3(z,50)
Output:
Quiver plot: A quiver plot or vector plot is a type of plotting that gives directional components of u, v, w using the cartesian components x, y, and z. For plotting of quiver plot use quiver3().
Syntax:
quiver3(X, Y, Z, U, V, W)
Example:
Matlab
% give the input value for x,% y and z[x,y,z]= meshgrid(0:0.1:5);  % using x, y and z give the % values for u,v and w u= sin(x).*cos(y);v= sin(x).*cos(y);w= sin(x).*cos(y);  %use quiver3() for 3d plottingquiver3(x,y,z,u,v,w);
Output:
MATLAB-graphs
Picked
MATLAB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Remove Noise from Digital Image in Frequency Domain Using MATLAB?
Differential or Derivatives in MATLAB
Boundary Extraction of image using MATLAB
Forward and Inverse Fourier Transform of an Image in MATLAB
Laplacian of Gaussian Filter in MATLAB
How to Solve Histogram Equalization Numerical Problem in MATLAB?
How to Apply Median Filter For RGB Image in MATLAB?
How to Normalize a Histogram in MATLAB?
Laplace Transform in MATLAB
What is Upsampling in MATLAB?