Reputation: 3405
I want to manually set my colorbar's
tick labels and its position horizontal. For example:
Min=0.8;
Max=12;
h = colorbar('horiz');
set(h,'location','southoutside')
set(h,'XTickLabel',{num2str(Min),'mm' ,num2str(Max)})
However, the above code repeats the tick labels label. How can I set number of tick manually?
I want my colorbar
to appear something like the following:
****----------------**** //colorbar
min [mm] max
Upvotes: 4
Views: 25634
Reputation: 11947
You can set the locations of your ticks like so:
set(h, 'XTick', [Min, (Min+Max)/2, Max])
Be aware that this will probably not look correct, unless the colour limits of your plot are set to the range [0.8, 12]. You can do this with:
set(gca, 'CLim', [Min, Max])
Furthermore, a better way of adding the units 'mm' to your colourbar would be as follows:
h = colorbar('horiz');
set(gca, 'CLim', [Min, Max])
set(h, 'XTick', [Min, Max])
set(h,'XTickLabel',{num2str(Min) ,num2str(Max)}) %# don't add units here...
xlabel(h, 'mm') %# ...use xlabel to add units
Upvotes: 7