Plot a 3D Contour in MATLAB
Contour plots are used to show 3D surfaces by plotting z- slides on a 2D surface. A contour plot is also called a line plot. In contour, we have 3 variables x, y, z. The x, y variables are used to give the values for z, ( z=f(x, y)). The x and y variables are usually in a grid called meshgrid.
There are various contour plots in MATLAB like contour, contourf, contour3, contourc, countourslice, clabel, and fcontour. In this article, we will see how to plot 3D contour in MATLAB. To plot 3D contour we will use countour3() to plot different types of 3D modules.
- contour3(X,Y,Z): Specifies the x and y coordinates for the values in Z.
- contour3(Z): Creates a 3-D contour plot containing the isolines of matrix Z, where Z contains height values on the x-y plane.
- contour3(___,levels): Specify levels as a scalar value n to display the contour lines at n automatically chosen levels (heights).
- contour3(___,LineSpec): Specifies the style and color of the contour line.
- Enter the inputs for x and y in meshgrid function.
- Pass the value for z using x and y in an equation.
- Use contour3 to plot 3d contour and to label the axis use label() method.
Below is the complete program:
Here is another example similar to the previous one.
MATLAB program to generate a 3D Contour: