How to add marker to matlab colorbar?
Asked Answered
T

1

0

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?

Tallis answered 13/5, 2013 at 22:27 Comment(0)
T
2

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');
Telekinesis answered 13/5, 2013 at 22:47 Comment(1)
Thank you Wakjah, but your solution woulnt make the critical tickmark standout from all the other tickmarks. Is there any way I could make it visually standout from the rest?Tallis

© 2022 - 2024 — McMap. All rights reserved.