Colour Associated with a Point in a Colourmap
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
DGM
2022년 2월 11일
편집: DGM
2022년 2월 11일
Here. This may be close to what you're trying to do. I don't know that it's really any clearer to do this than it is to put the tick labels on the breakpoints as I did in the prior example. This way does eat up more figure space with the long labels though.
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;
bp = linspace(clim(1),clim(2),nlevels+1);
segcenter = bp(1:end-1) + range(clim)/(nlevels*2);
tlab = split(sprintf('%.2f <σS^2< %.2f\n',[bp(1:end-1); bp(2:end)]),newline);
hc.Ticks = segcenter;
hc.TickLabels = tlab;
% need to adjust the axes position to make room for the cb labels
hax = gca;
oldaxw = hax.Position(3);
hax.Position(3) = oldaxw*0.85;
댓글 수: 3
Image Analyst
2022년 2월 11일
편집: Image Analyst
2022년 2월 11일
@Tb if it's at the bottom of the color how would you know which color the range applies to? You'd have to just use tick labels that mention the first number if you're going to do it that way since the first number indicates the start of the color range and the numbers go up from there.
By the way, did you see my answer below where you can specify the range instead of just taking what you get (the default)?
추가 답변 (1개)
Image Analyst
2022년 2월 10일
See the caxis() function.
댓글 수: 3
DGM
2022년 2월 11일
편집: DGM
2022년 2월 11일
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
2022년 2월 11일
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).
참고 항목
카테고리
Help Center 및 File Exchange에서 Colormaps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!