Main Content

改变等高线图的填充颜色

此示例演示如何更改已填充等高线图的颜色。

更改颜色图

通过改变颜色图设置已填充等高线图的颜色。将预定义的颜色图名称 hot 传递给 colormap 函数。

[X,Y,Z] = peaks;
figure
contourf(X,Y,Z,20)
colormap(hot)
title('Hot Colormap')

Figure contains an axes object. The axes object with title Hot Colormap contains an object of type contour.

控制颜色值到颜色图的映射

通过将颜色图范围设置为比矩阵 Z 中的值大得多的范围值,保证只使用 hot 颜色图中间的颜色。clim 函数用于控制数据值到颜色图的映射。使用此函数设置颜色图范围。

clim([-20,20])
title('Center of Hot Colormap')

Figure contains an axes object. The axes object with title Center of Hot Colormap contains an object of type contour.

在 R2022a 之前,使用 caxis([-20 20]) 更改颜色图范围。

另请参阅

| |