How to add marker to matlab colorbar?

我的梦境 提交于 2019-12-11 14:16:05

问题


I want to add a tarker/special tick mark by specific values in my matlab colorbars. For example, lets say I have a colorbar scale from -20 to 60 and my critical value is 37.53, how can I add a marker by that value of the colorbar?


回答1:


The colorbar is really an axes object, so you can add tickmarks like you would any 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);

Edit: In the comments, you have asked for a way to make the custom tick mark stand out amongst the rest. You can make a single bold tick mark using the following method:

% 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');


来源:https://stackoverflow.com/questions/16532176/how-to-add-marker-to-matlab-colorbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!