How to label a colormap

9 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2012-9-2
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 个评论
Daniel
Daniel 2012-9-3
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by