如何将标记/符号添加到colorbar

时间:2016-09-20 12:15:35

标签: matlab matlab-figure symbols colorbar

我想在我的MATLAB colorbar中添加标记/特殊刻度标记。例如,假设我的颜色条比例从-23,我的临界值为-1.8,如何按符号/标记添加值的标记?

enter image description here

2 个答案:

答案 0 :(得分:4)

这是另一种选择 - 只需在特定值处添加/更改刻度标签:

MarkTxt = '<-Mark';
imagesc(rand(10)-2) % something to plot
colormap('jet')
CB = colorbar;

% in case you DON'T want the value to appear:
value = -1.8;
t = find(CB.Ticks==value);
if ~isempty(t)
    CB.TickLabels{t} = MarkTxt;
else
    [CB.Ticks,ord] = sort([CB.Ticks value],'ascend');
    t = CB.Ticks==value;
    CB.TickLabels{t} = MarkTxt;
end

%% OR - in case you want the value to appear:
value = -1.24;
t = find(CB.Ticks==value);
if ~isempty(t)
    CB.TickLabels{t} = [CB.TickLabels{t} MarkTxt];
else
    [CB.Ticks,ord] = sort([CB.Ticks value],'ascend');
    t = CB.Ticks==value;
    CB.TickLabels{t} = [CB.TickLabels{t} MarkTxt];
end

没有价值: CB mark

具有以下价值: CB mark value

答案 1 :(得分:2)

您只需在绘图区域外添加text,然后将其用于标记:

A = rand(15);
f=figure;
imagesc(A);
text(7,7,'X','Color','red') % Put a red X in the middle
text(17.5,size(A,1)*(1-A(7,7)),'<marker'); % Set a marker on the colour bar for the middle point
colorbar

结果是:

enter image description here

我还没有找到方法在颜色条上绘制标记,因为颜色条不是我可以在{{{ 1}}由于某种原因。