필터 지우기
필터 지우기

How to label a colormap

조회 수: 9 (최근 30일)
Daniel
Daniel 2012년 9월 2일
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