How to mark colorbar shortcuts in MATLAB?

I want to manually set the colorbar's label tags and its horizontal position. For instance:

  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 label of label labels. How to set the number of ticks manually? I want my colorbar look something like this:

 ****----------------**** //colorbar min [mm] max 
+4
source share
1 answer

You can set the location of your ticks as follows:

 set(h, 'XTick', [Min, (Min+Max)/2, Max]) 

Keep in mind that this probably will not look correct if the color limits of your graph are not set in the range [0.8, 12]. You can do this with:

 set(gca, 'CLim', [Min, Max]) 

In addition, the best way to add β€œmm” units to your color 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 
+7
source

Source: https://habr.com/ru/post/1393763/


All Articles