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

lokaqttq  于 2023-01-31  发布在  Matlab
关注(0)|答案(1)|浏览(105)

我尝试在Matlab中创建一个代码,该代码将生成一个表面Map,该Map具有在2或3个不同断点处定义的颜色条,例如,低于0.8时为白色,0.8-1.2时为绿色,大于1.2时为蓝色(或0.6,0.8,1 for 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
a64a0gku

a64a0gku1#

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

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

% apply
hb.Ticks = cticks ;
hb.TickLabels = cticklabels ;

相关问题