surfc
Create three matrices of the same size. Then plot them as a surface and display a contour plot under the surface plot. The surface uses
Z
for 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 usesZ
for height andC
for color. Specify the colors using a colormap, which uses single numbers to stand for colors on a spectrum. When you use a colormap,C
is the same size asZ
. Add a color bar to the graph to show how the data values inC
correspond 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
FaceColor
name-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
sc
to 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 theEdgeColor
properties.
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
ZLocation
property.Display the
peaks
data set as a surface plot with the contours at the minimum z-level. Specify a return argument when you call thesurfc
function so that you can access theContour
object.
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()