surfcCreate three matrices of the same size. Then plot them as a surface and display a contour plot under the surface plot. The surface uses
Zfor both height and color.
[X,Y] = meshgrid(1:0.5:10,1:20); Z = sin(X) + cos(Y); surfc(X,Y,Z) fig2plotly()
Specify the colors for a surface and a contour plot by including a fourth matrix input,
C. The surface plot usesZfor height andCfor color. Specify the colors using a colormap, which uses single numbers to stand for colors on a spectrum. When you use a colormap,Cis the same size asZ. Add a color bar to the graph to show how the data values inCcorrespond to the colors in the colormap.
[X,Y] = meshgrid(-3:.125:3); Z = peaks(X,Y); C = X.*Y; surfc(X,Y,Z,C) colorbar fig2plotly()
Create a blue surface plot with a contour plot underneath it by specifying the
FaceColorname-value pair with'b'as the value. To allow further modifications, assign the graphics array containing the surface and contour objects to the variablesc.
[X,Y] = meshgrid(-5:.5:5); Z = Y.*sin(X) - X.*cos(Y); sc = surfc(X,Y,Z,'FaceColor','b'); fig2plotly()
Index into
scto access and modify properties of the surface and contour plots after they are created. The surface plot is accessible assc(1)and the contour plot assc(2). For example, change the edge colors of the two plots by setting theEdgeColorproperties.
sc(1).EdgeColor = 'r'; sc(2).EdgeColor = 'b'; fig2plotly()
The contour lines appear at the minimum z-level by default, but you can change the location by setting the
ZLocationproperty.Display the
peaksdata set as a surface plot with the contours at the minimum z-level. Specify a return argument when you call thesurfcfunction so that you can access theContourobject.
Z = peaks; sc = surfc(Z); fig2plotly()
Get the current axes and extend the upper limit of the z-axis to
15. Then move the contours to the maximum z-level.
ax = gca; ax.ZLim(2) = 15; sc(2).ZLocation = 'zmax'; fig2plotly()