Effacer les filtres
Effacer les filtres

How to label a colormap

9 vues (au cours des 30 derniers jours)
Daniel
Daniel le 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

Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaires
Daniel
Daniel le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Blue dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by