【发布时间】:2016-09-20 12:15:34
【问题描述】:
【问题讨论】:
标签: matlab matlab-figure symbols colorbar
【问题讨论】:
标签: matlab matlab-figure symbols colorbar
执行此操作的一种方法是获取colorbar 位置,计算您想要标记的位置,然后在其中放置annotation object(如箭头):
% Plot sample data, displaying color bar and getting its limits:
data = peaks();
imagesc(data);
hBar = colorbar();
cLimits = caxis();
hold on;
% Select and plot a point of interest:
point = [31 15];
value = data(point(1), point(2));
plot(point(2), point(1), 'r+');
% Compute location of color bar pointer and make annotation:
barPos = get(hBar, 'Position');
xArrow = barPos(1)+barPos(3)/2+[0.05 0];
yArrow = barPos(2)+barPos(4)*(value-cLimits(1))/diff(cLimits)+[0 0];
hArrow = annotation('textarrow', xArrow, yArrow, ...
'String', num2str(value, '%.2f'), 'Color', 'r');
如果调整图形大小,注释对象的位置可能会相对于彩条发生偏移。避免这种情况的一种方法是使用以下代码调整轴和颜色条的大小调整行为:
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
【讨论】:
您只需在绘图区域外添加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
结果:
我还没有找到一种方法在 颜色条上绘制标记,因为颜色条不是我可以在 uistack 中使用的绘图子项之一某种原因。
【讨论】: