如何将标记添加到matlab colorbar?

时间:2013-05-13 22:27:19

标签: matlab graphing colorbar

我想在matlab颜色栏中按特定值添加一个tarker /特殊刻度标记。例如,假设我的颜色条范围为-20到60,我的临界值为37.53,如何通过颜色条的值添加标记?

1 个答案:

答案 0 :(得分:2)

colorbar实际上是一个axes对象,因此您可以像添加任何轴一样添加标记:

myTick = 37.53;

c = colorbar();
ticks = get(c, 'YTick');
% Add your tick and sort so it's monotonically increasing
ticks = sort([ticks myTick]);
set(c, 'YTick', ticks);

修改:在评论中,您已经要求一种方法使自定义刻度标记在其余部分中脱颖而出。您可以使用以下方法制作单个粗体刻度线:

% Here is an example plot
pcolor(rand(100));
c = colorbar();
myTick = 0.45; % Change this for real data

% Create a copy of the colorbar with transparent background and overlay
c2 = copyobj(c, gcf);
alpha(get(c2, 'Children'), 0);
set(c2, 'Color', 'none');
set(c2, 'Position', get(c, 'Position'));

% Give the copy a single tick mark and set its font style
set(c2, 'YTick', myTick);
set(c2, 'FontWeight', 'bold');