且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Matlab:如何为同一图中的不同表面分配不同的颜色图/颜色条

更新时间:2023-01-28 11:48:03

基本思想是连接颜色图,然后移动/缩放不同绘图句柄的颜色数据 (CData)与颜色图的所需部分对齐.因此,在不知道您的自定义函数或特定数据是什么的情况下,您可以执行类似 colormap(topopathy(64); redwhitegreen(64)) 之类的操作,然后缩放 CDatab 进入范围 [1,64] 和 cCData 进入范围 [65,128].

The basic idea is that you concatenate the colormaps, and then shift/scale the color data (CData) of the different plot handles to line up with the desired portions of the colormap. So, without knowing what your custom functions or specific data are, you could do something like colormap(topobathy(64); redwhitegreen(64)) and then scale the CData of b into the range [1,64] and the CData of c into the range [65,128].

MathWorks 网站上有一个 优秀 指南,解释了所有这些(甚至使用 surf()pcolor() 就像你的例子):

There is an excellent guide on the MathWorks website that explains all this (even uses surf() and pcolor() like your example):

http://www.mathworks.com/support/tech-notes/1200/1215.html#Example_1

对于颜色条,您可以以类似的方式伪造刻度和标签.这是为上述示例制作颜色条的粗略镜头:

For the colorbar, you can just fake out the ticks and labels in a similar manner. Here is rough shot at making a color bar for the above example:

h = colorbar;
ticks = [1 16:16:64 64:16:128];
ticks(5:6) = [62 66];
set(h, 'YTick', ticks);

labels = num2str(repmat(linspace(min(Z(:)), max(Z(:)), 5), 1, 2)', 2);
set(h, 'YTickLabel', labels)