Re-range gray color level from 0-192 in contourf plot
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Tina Hsiao
il 30 Mar 2021
Risposto: Cris LaPierre
il 30 Mar 2021
Hello, seek help for re-range gray color level from 0-192 in contourf. I would like to get the color bar shows 0-192. The code as below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/567939/image.png)
clear all
X = [-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150];
Y = [-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150;-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125;-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100;-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75;-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50;-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25;0,0,0,0,0,0,0,0,0,0,0,0,0;25,25,25,25,25,25,25,25,25,25,25,25,25;50,50,50,50,50,50,50,50,50,50,50,50,50;75,75,75,75,75,75,75,75,75,75,75,75,75;100,100,100,100,100,100,100,100,100,100,100,100,100;125,125,125,125,125,125,125,125,125,125,125,125,125;150,150,150,150,150,150,150,150,150,150,150,150,150];
r_M =[27,19,12,8,3,3,1,0,0,3,9,15,23;30,20,14,9,5,3,1,0,0,3,7,12,21;33,23,15,11,6,3,2,1,2,4,7,13,20;33,23,15,12,7,4,2,2,2,4,7,12,19;30,20,16,13,8,5,3,3,4,5,7,12,20;27,20,16,14,9,6,4,4,5,5,7,12,21;27,20,16,14,8,5,3,3,4,4,6,11,20;27,19,15,13,7,5,3,2,3,4,6,12,21;25,18,14,12,6,4,2,2,3,4,6,11,21;28,19,15,13,7,4,2,2,3,4,7,13,23;29,19,15,13,8,5,3,2,2,4,7,15,25;33,22,17,14,8,5,3,2,2,3,5,12,23;37,25,19,15,8,6,4,2,1,2,2,10,19];
figure(104)
contourf(X,Y,r_M,2560,'LineColor','none')
colormap(flipud(gray(256)));
colorbar
set(gca,'xtick',[])
set(gca,'ytick',[])
0 Commenti
Risposta accettata
Cris LaPierre
il 30 Mar 2021
I think you want caxis. Note this will rescale your colormap, meaning the darkest color will now be associated with 192 instead of 37. This means your figure colors will be shifted to the white end of the spectrum.
X = [-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150;-150,-125,-100,-75,-50,-25,0,25,50,75,100,125,150];
Y = [-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150,-150;-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125,-125;-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100,-100;-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75,-75;-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50,-50;-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25,-25;0,0,0,0,0,0,0,0,0,0,0,0,0;25,25,25,25,25,25,25,25,25,25,25,25,25;50,50,50,50,50,50,50,50,50,50,50,50,50;75,75,75,75,75,75,75,75,75,75,75,75,75;100,100,100,100,100,100,100,100,100,100,100,100,100;125,125,125,125,125,125,125,125,125,125,125,125,125;150,150,150,150,150,150,150,150,150,150,150,150,150];
r_M =[27,19,12,8,3,3,1,0,0,3,9,15,23;30,20,14,9,5,3,1,0,0,3,7,12,21;33,23,15,11,6,3,2,1,2,4,7,13,20;33,23,15,12,7,4,2,2,2,4,7,12,19;30,20,16,13,8,5,3,3,4,5,7,12,20;27,20,16,14,9,6,4,4,5,5,7,12,21;27,20,16,14,8,5,3,3,4,4,6,11,20;27,19,15,13,7,5,3,2,3,4,6,12,21;25,18,14,12,6,4,2,2,3,4,6,11,21;28,19,15,13,7,4,2,2,3,4,7,13,23;29,19,15,13,8,5,3,2,2,4,7,15,25;33,22,17,14,8,5,3,2,2,3,5,12,23;37,25,19,15,8,6,4,2,1,2,2,10,19];
contourf(X,Y,r_M,2560,'LineColor','none')
colormap(flipud(gray(256)));
colorbar
axis off
caxis([0 192])
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Purple in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!