surfCreate three matrices of the same size. Then plot them as a surface. The surface plot uses
Zfor both height and color.
[X,Y] = meshgrid(1:0.5:10,1:20); Z = sin(X) + cos(Y); surf(X,Y,Z) fig2plotly()
Specify the colors for a surface 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(1:0.5:10,1:20); Z = sin(X) + cos(Y); C = X.*Y; surf(X,Y,Z,C) colorbar fig2plotly()
Specify the colors for a surface plot by including a fourth matrix input,
CO. The surface plot usesZfor height andCOfor color. Specify the colors using truecolor, which uses triplets of numbers to stand for all possible colors. When you use truecolor, ifZism-by-n, thenCOism-by-n-by-3. The first page of the array indicates the red component for each color, the second page indicates the green component, and the third page indicates the blue component.
[X,Y,Z] = peaks(25); CO(:,:,1) = zeros(25); % red CO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % green CO(:,:,3) = ones(25).*linspace(0,1,25); % blue surf(X,Y,Z,CO) fig2plotly()
Create a semitransparent surface by specifying the
FaceAlphaname-value pair with0.5as the value. To allow further modifications, assign the surface object to the variables.
[X,Y] = meshgrid(-5:.5:5); Z = Y.*sin(X) - X.*cos(Y); s = surf(X,Y,Z,'FaceAlpha',0.5) fig2plotly()
fig2plotly()s = Surface with properties: EdgeColor: [0 0 0] LineStyle: '-' FaceColor: 'flat' FaceLighting: 'flat' FaceAlpha: 0.5000 XData: [21x21 double] YData: [21x21 double] ZData: [21x21 double] CData: [21x21 double] Show all properties
Use
sto access and modify properties of the surface object after it is created. For example, hide the edges by setting theEdgeColorproperty.
s.EdgeColor = 'none'; fig2plotly()