在Matlab中使用2-3个用户定义的断点颜色条创建表面地图



我试图在Matlab中创建一个代码,该代码将生成一个表面地图,该地图在2或3个不同的断点处定义了一个颜色条,例如低于0.8它将是白色的,从0.8-1.2它将是绿色的,大于1.2将是蓝色的(或0.6,0.8,1为3个断点)。我有一个代码,将与一个定义的断点运行,但我有麻烦弄清楚如何运行多个断点。它们需要是在颜色栏中没有渐变过渡的已定义的单一颜色。有什么建议,我可以做些什么来定义2-3断点颜色条在用户定义的中断?

%% Two Toned Map
% define colormap and breakpoint
cmap = [0 0 1 ; 1 1 1; 1 0 1];    
breakpoint = [0.7 ; 1.2]; %CHANGE VALUE
%create a color matrix with only 2 values:
%   where Profile < breakpoint => ColorData=0
%   where Profile > breakpoint => ColorData=1
ColorData= zeros(size(Profile)) ;
ColorData(Profile>=breakpoint(2)) = 2 ;
ColorData(Profile<=breakpoint(1)) = 1 ;
%Plot the surface, specifying the color matrix we want to have applied
hs = surf( xa, ya, Profile, ColorData, 'EdgeColor','none' ) ;
colormap(cmap) ;
hb = colorbar ;
set (gca, 'xdir', 'reverse')
set (gca, 'ydir', 'reverse')
set (gca, 'DataAspectRatio',[1 1 1])
xlim([0 80+deltax])
ylim([0 100+deltay])
%Now adjust colorbar ticks and labels
cticks = [0.25 0.5 0.75] ; % positions of the ticks we keep
% build labels
bpstr = num2str(breakpoint) ;
cticklabels = {['<' bpstr] ; bpstr ; ['>' bpstr]}
% apply
hb.Ticks = cticks ;
hb.TickLabels = cticklabels ;
title('Sheared 4mm') %CHANGE VALUE

您需要修改标签构造代码以处理多个断点。

%Now adjust colorbar ticks and labels
cticks = (1:numel(breakpoint))*(numel(breakpoint)/(numel(breakpoint)+1));
cticklabels = breakpoint;
% apply
hb.Ticks = cticks ;
hb.TickLabels = cticklabels ;

最新更新