Home > Blockchain >  Matlab - Add a specific tick on a colorbar
Matlab - Add a specific tick on a colorbar

Time:10-28

I'm representing a surface using "surf" function, with a colorbar. I would like to keep the default ticks of the colorbar, but add a custom tick on this colorbar, at a specific value (that I could make red to distinguish it from other ticks for example). Any idea on how to add a custom tick like that with keeping existing ticks on the colorbar ?

Thanks

CodePudding user response:

As plot

Similarly, you could use annotatation exclusively to just get a red label, it's a little more convoluted to get everything lined up correctly, you have to make sure the text box is wide enough to be on a single line and vertically aligned to the middle to get the position right:

h = colorbar; 
newTick = 0.75;
pos = h.Position;
r = (newTick - min(h.Ticks))/(max(h.Ticks)-min(h.Ticks));
h = 0.2;
annotation( 'textbox', [pos(1) pos(3)/2, (pos(2) pos(4)*r)-(h/2), pos(3)*2, h], ...
    'color', [1,0,0], 'string', ['- ' num2str(newTick)], 'linestyle', 'none', ...
    'VerticalAlignment', 'middle' );

plot2

  • Related