How to make a discrete colorbar with specified intervals?

조회 수: 197(최근 30일)
Yoni Verhaegen -WE-1718-
Yoni Verhaegen -WE-1718- 2021년 2월 7일
답변: Cris LaPierre 2021년 2월 7일
Hi all,
I want to change the default colorbar to a discrete one (i.e. with blocks) of non-evenly spaced intervals.
I uploaded an image as an attechment to show what I would like.
I hope someone can help.
Thanks

답변(1개)

Cris LaPierre
Cris LaPierre 2021년 2월 7일
Your colorbar is set by the resolution of your colormap. If you want a colobar with 16 colors, set a colormap that only has 16 defined colors. Here's an example that recreates the "block" colorbar.
contourf(rescale(peaks,0,500))
C=parula(15);
C(end+1,:)=1;
colormap(flipud(C))
colorbar('Ticks',linspace(0,500,17),...
'TickLabels',["" "0.01" "0.5" "1" "1.5" "2" "5" "10" "15" "20" "25" "50" "75" "100" "250" "500" ">500"]);

Community Treasure Hunt

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

Start Hunting!

Translated by