How to label a colormap

14 views (last 30 days)
Daniel
Daniel on 2 Sep 2012
I would like to label a colormap with text to indicate what it represents, and the min and max values. My plots come out inconsistant and repeat the labels I want. For example, I might want the min value on the bottom of a vertical colormap, the max value at the top and the word 'Trec' in the middle. Here is my code to date but the colorbar produced shows from top to bottom: "Trec -50 40 Trec -50" instead of the desired "50 Trec -40"
colormap(jet); %defines bype of color map for points in scatter plot
cmin = -50; cmax = 40; V=[cmin, cmax];
caxis(V); %set color map range
subplot(2,1,1) %scatter plot
scatter(newData1.data(:,RH_TAM_col),newData1.data(:,RH_CIT_col),10,newData1.data(:,6))
hcb = colorbar('YTickLabel', {num2str(cmin),'Trec', num2str(cmax)}); %add colorbar scale to plot
set(hcb,'YTickMode','manual'); %colorbar handle hcb. Keep color bar labels from changing when resizing.
grid on

Accepted Answer

Walter Roberson
Walter Roberson on 2 Sep 2012
You need to set the YTick as well, or else the number of ticks will usually not match the number of labels you have provided.
Note: if you do supply YTick, then YTickMode will be set to 'manual' on your behalf.
  4 Comments
Daniel
Daniel on 3 Sep 2012
OK, thanks. I think I may have it working now. My new code:
colormap(jet); %defines bype of color map for points in scatter plot cmin = -50; cmax = 40; V=[cmin, cmax]; subplot(2,1,1) %scatter plot scatter(newData1.data(:,RH_TAM_col),newData1.data(:,RH_CIT_col),10,newData1.data(:,6)) caxis(V); %set color map range hcb = colorbar('YTick', [cmin 0 cmax],'YTickLabel', {num2str(cmin),'Trec', num2str(cmax)}); %add colorbar scale to plot

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!