MATLAB meshc in MATLAB®
Learn how to make 4 meshc charts in MATLAB, then publish them to the Web with Plotly.
Display Contour Plot Under Mesh Plot
Create three matrices of the same size. Then plot them as a mesh plot with a contour plot underneath. The mesh plot uses Z
for both height and color.
[X,Y] = meshgrid(-3:.125:3); Z = peaks(X,Y); meshc(X,Y,Z) fig2plotly()
Specify Colormap Colors for Mesh and Contour Plot
Specify the colors for a mesh and contour plot by including a fourth matrix input, C
. The plots use Z
for height and C
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 as Z
. Add a color bar to the graph to show how the data values in C
correspond to the colors in the colormap.
[X,Y] = meshgrid(-3:.125:3); Z = peaks(X,Y); C = X.*Y; meshc(X,Y,Z,C) colorbar fig2plotly()
Modify Appearance of Mesh and Contour Plots
Create a mesh plot with a contour plot underneath it. To allow further modifications, assign the graphics array containing the surface and contour objects to the variable sc
.
[X,Y] = meshgrid(-5:.5:5); Z = Y.sin(X) - X.cos(Y); sc = meshc(X,Y,Z);
Index into sc
to access and modify properties of the mesh and contour plots after they are created. The mesh plot is accessible as sc(1)
and the contour plot as sc(2)
. For example, change the edge colors of the two plots by setting the EdgeColor
properties.
sc(1).EdgeColor = 'r'; sc(2).EdgeColor = 'b'; fig2plotly()
Change Location of Contour Lines
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 mesh plot with the contours at the minimum z-level. Specify a return argument when you call the meshc
function so that you can access the Contour
object.
Z = peaks; sc = meshc(Z);
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()