# MATLAB 绘制颜色图

## 在 MATLAB 中使用 `mesh()` 函数绘制颜色图

``````a = 0:0.1:10;
z = [sin(a);sin(a)];
mesh(z)
colorbar
``````

``````a = 0:0.1:10;
z = [sin(a);sin(a)];
mesh(z)
colormap summer
colorbar
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
mesh(x,y,z)
colorbar
``````

``````a = 0:0.1:30;
z = [sin(a); sin(a)];
mesh(z)
colorbar
view(2)
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
mesh(x,y,z,'FaceColor','Flat')
colorbar
``````

## 在 MATLAB 中使用 `meshc()` 函数绘制颜色图

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
meshc(x,y,z)
colorbar
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
meshc(x,y,z)
colorbar
colormap winter
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
sc = meshc(x,y,z)
sc(1).EdgeColor = 'r';
sc(2).EdgeColor = 'b';
colorbar
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
sc = meshc(x,y,z)
sc(2).ZLocation = 'zmax';
colorbar
``````

## 在 MATLAB 中使用 `meshz()` 函数绘制颜色图

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
meshz(x,y,z)
colorbar
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
meshz(x,y,z)
colorbar
colormap winter
``````

``````a = 0:0.1:10;
b = 0:10;
[x,y] = meshgrid(a,b);
z = sin(x) + sin(y);
sc = meshz(x,y,z)
sc(1).EdgeColor = 'g';
``````

## 在 MATLAB 中使用 `surf()` 函数绘制颜色图

`surf()` 函数的功能与 `mesh()` 函数的功能相同，只是区别在于 `surf()` 函数绘制的矩阵为纯色，而 `mesh()` 函数绘制的矩阵则为无色颜色。除此之外，`surf()``mesh()` 是相同的功能。请查看上述 `mesh()` 函数。查看此网页以获得有关 `surf()` 函数的更多信息。

• MATLAB 自定义图例
• MATLAB 轴限值