contourf
Define
Z
as a function of two variables. In this case, call thepeaks
function to createZ
. Then display a filled contour plot ofZ
, letting MATLAB® choose the contour levels.
Z = peaks; contourf(Z) fig2plotly()
Define
Z
as a function of two variables,X
andY
. Then display contours at 10 levels ofZ
.
x = linspace(-2*pi,2*pi); y = linspace(0,4*pi); [X,Y] = meshgrid(x,y); Z = sin(X) + cos(Y); contourf(X,Y,Z,10) fig2plotly()
Define
Z
as a function ofX
andY
. In this case, call thepeaks
function to createX
,Y
, andZ
. Then display contours at levels2
and3
.The white region corresponds to the heights less than
2
. The purple region corresponds to heights between2
and3
. And the yellow region corresponds to heights that are greater than3
.
[X,Y,Z] = peaks(50); contourf(X,Y,Z,[2 3],'ShowText','on') fig2plotly()
Define
Z
as a function ofX
andY
. In this case, call thepeaks
function to createX
,Y
, andZ
. Then display contours atZ = 2
.
[X,Y,Z] = peaks; contourf(X,Y,Z,[2 2]) fig2plotly()
Create a contour plot, and specify the dashed line style.
[X,Y,Z] = peaks; contourf(X,Y,Z,'--') fig2plotly()
Create a filled contour plot. Make the contour lines thicker by setting the
LineWidth
property to3
.
Z = peaks; [M,c] = contourf(Z); c.LineWidth = 3; fig2plotly()
Insert
NaN
values wherever there are discontinuities on a surface. Thecontourf
function does not draw contour lines in those regions.Define matrix
Z
as a sampling of thepeaks
function. Replace all values in column26
withNaN
values. Then plot the contours of the modifiedZ
matrix.
Z = peaks; Z(:,26) = NaN; contourf(Z) fig2plotly()