meshCreate three matrices of the same size. Then plot them as a mesh plot. The plot uses
Zfor both height and color.
[X,Y] = meshgrid(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; mesh(X,Y,Z) fig2plotly()
Specify the colors for a mesh plot by including a fourth matrix input,
C. The mesh 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(-8:.5:8); R = sqrt(X.^2 + Y.^2) + eps; Z = sin(R)./R; C = X.*Y; mesh(X,Y,Z,C) colorbar fig2plotly()
Specify the colors for a mesh plot by including a fourth matrix input,
CO. The mesh 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 mesh(X,Y,Z,CO) fig2plotly()
Create a semitransparent mesh 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 = mesh(X,Y,Z,'FaceAlpha','0.5') fig2plotly()
fig2plotly()s = Surface with properties: EdgeColor: 'flat' LineStyle: '-' FaceColor: [1 1 1] FaceLighting: 'none' 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 mesh plot after it is created. For example, add color to the face of the mesh plot by setting theFaceColorproperty.
s.FaceColor = 'flat'; fig2plotly()