Colour Associated with a Point in a Colourmap
Mostrar comentarios más antiguos
I have made a colourplot using the pcolor command in MATLAB. However, I am trying to make a colourbar which shows roughly the range of data a single colour encompasses. I am not sure how to even start coding this, any help would be massively appreciated.
The data I am using is attached, and the following code is what I am running.
load lambda300.mat;
load delta300.mat;
load maxPF300.mat;
figure;
s = pcolor(lambda_array/1e-19,delta_array/1e-19,maxPF300);
colormap turbo(7);
colorbar('Ticks',[1,4.55,8,11.5,15,18.5,22],...
'TickLabels',{'0<σS^2<3.5','3.5<σS^2<7','7<σS^2<10.5', ...
'10.5<σS^2<14','14<σS^2<17.5', '17.5<σS^2<21', '21<σS^2<25',}, 'fontsize', 15);
shading interp;
The placing of the ticks and the values associated with them has very much been a stab in the dark. Therefore, I would like to know which colour approximately maps which range of values of the maxPF300 data, and is there an automated way for doing this.
Thank you very much!
2 comentarios
colorbar('on')
But I think you want something a bit more in depth. Could you pass along the data you're plotting?
Tb
el 10 de Feb. de 2022
Respuesta aceptada
Más respuestas (1)
Image Analyst
el 10 de Feb. de 2022
0 votos
See the caxis() function.
3 comentarios
Consider the example:
x = 1:100;
y = x';
z = x+y;
nlevels = 7;
hp = pcolor(x,y,z); hold on
shading flat
hc = colorbar;
colormap(jet(nlevels))
clim = caxis
hc.Ticks = linspace(clim(1),clim(2),nlevels+1);
To answer your question, the colorbar has 7+1 breakpoints, but the breakpoints are spaced by caxis()/7.
Image Analyst
el 11 de Feb. de 2022
You call caxis and send it the values. You didn't do that. You just got caxis and found out what the default values are. For example if you want the 7 colors to go from 30 to 150 you'd do
caxis([30, 150]);
so anything 30 or less will show up as blue, then you'd have the 7 colors for values up to 150. If your data is 150 or above, those values will show up at the top color in the colormap (red for the image you showed above).
Categorías
Más información sobre Color and Styling en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

