How to Plot 3D Contour in MATLAB
This tutorial will discuss creating a 3D contour plot using the contour3()
function in MATLAB.
Create a 3D Contour Plot Using the contour3()
Function in MATLAB
We can use MATLAB’s built-in function contour3()
to create a 3D contour plot. A contour plot is a plot of isolines with different colors according to values.
The color given to the line depends on its value. The colder color corresponds to low values, and the hotter color corresponds to high values.
For example, let’s plot a 3D contour plot of a sphere using the sphere()
and the contour3()
function. See the code below.
[x,y,z] = sphere(100);
contour3(x,y,z);
Output:
We can also set some properties of the contour plot like the line levels, line specifications, line style, line color, line labels, line width, and label spacing.
We can set the value of levels to any scalar or vector value. We can also set the line specification like the color and line style simultaneously using the LineSpec
property.
By default, the show text
is set to off, but we can turn it on and show any text on the plot. By default, the line width is 0.5, but we can change to any positive scaler value using the LineWidth
property.
The default value of the label spacing is 144, but we can set it to any scalar using the LabelSpacing
property. We can give a title to the plot, and we can also set the labels of the plot.
For example, let’s change some properties of the above graph. See the code below.
[x,y,z] = sphere(100);
contour3(x,y,z,20,'Color','red','LineWidth',1.5,'LineStyle','-.')
Output:
We can also create an object of the contour3()
function, which we can use to change the properties of the plot after it is created.
Related Article - MATLAB Plot
- MATLAB Waterfall Plot
- How to Create Polar Plot in MATLAB
- How to Plot Multiple Data Sets on a Single Scatter Plot in MATLAB
- The caxis() Function in MATLAB
- How to Use Greek Symbols in Bar Graph Labels in MATLAB
- How to Plot Exponential Function of Any Equation in MATLAB