Question

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?

Was it helpful?

Solution

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');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top