Matlab 如何将标记/符号添加到颜色栏

Matlab 如何将标记/符号添加到颜色栏,matlab,matlab-figure,symbols,colorbar,Matlab,Matlab Figure,Symbols,Colorbar,我想在我的MATLABcolorbar中添加一个标记/特殊的记号。例如,假设我有一个从-2到3的色条刻度,我的临界值是-1.8,我如何通过符号/标记添加值的标记 您只需在绘图区域外添加并将其用于标记: 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 mar

我想在我的MATLAB
colorbar
中添加一个标记/特殊的记号。例如,假设我有一个从
-2
3
的色条刻度,我的临界值是
-1.8
,我如何通过符号/标记添加值的标记

您只需在绘图区域外添加并将其用于标记:

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
A=rand(15);
f=数字;
c(A);
文本(7,7,‘X’,‘颜色’,‘红色’)%在中间放红色X。

文本(17.5,大小(A,1)*(1-A(7,7)),“一种方法是获取位置,计算您想要标记的位置,并在那里放置一个(如箭头所示):

如果调整图形的大小,注释对象的位置可能会相对于颜色栏发生移动。避免这种情况的一种方法是使用以下代码调整轴和颜色栏的大小行为:

axesPos = get(gca, 'Position');
set(hBar, 'Location', 'manual');
set(gca, 'Position', axesPos);

这将允许注释对象固定在颜色栏上的适当位置。

这里还有另一个选项-只需在特定值处添加/更改记号标签:

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
MarkTxt=
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