필터 지우기
필터 지우기

How do you remove non-integer values from a colorbar?

조회 수: 17 (최근 30일)
L'O.G.
L'O.G. 2022년 9월 15일
답변: Star Strider 2022년 9월 15일
My image only has integer values, so including the non-integer values in the colorbar is something I'd like to not do.

답변 (2개)

Kevin Holly
Kevin Holly 2022년 9월 15일
Let's say this is an image with a colorbar with non-integer values:
Img = randi(255,25);
imagesc(Img)
h=colorbar;
h.Ticks = [25:55.5:250];
You can change the Ticks with the handle as such:
Img = randi(255,25);
imagesc(Img)
h=colorbar;
h.Ticks = [25:25:250];
  댓글 수: 1
Kevin Holly
Kevin Holly 2022년 9월 15일
편집: Kevin Holly 2022년 9월 15일
You can change your colormap
Img = randi(4,25)-2;
imagesc(Img)
cmap = [0 0 1; 0 1 0; 1 1 1; 1 0 0];
colormap(cmap)
h=colorbar;
h.Ticks=-1:2;
Knowing I have 3 sections, I will change my colormap to only have 3 colors.
imagesc(Img)
cmap = [0 0 1; 1 1 1; 1 0 0];
colormap(cmap)
h=colorbar;
h.Ticks=-1:2;

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 2022년 9월 15일
This required some coding gymnastics, however it may be what you want —
cm = [1 0 0; 1 1 1; 0 0 1]; % Basic Colormap
cmi = interp1([-1; 0; 2], cm, (-1:2)) % interpolated Colormap
cmi = 4×3
1.0000 0 0 1.0000 1.0000 1.0000 0.5000 0.5000 1.0000 0 0 1.0000
M = randi([-1 2],9) % Matrix
M = 9×9
0 0 1 2 -1 1 -1 -1 -1 1 2 1 0 -1 2 0 -1 0 0 1 2 -1 0 1 2 -1 0 1 1 -1 2 1 -1 -1 1 2 -1 -1 2 0 2 1 1 -1 -1 -1 -1 2 2 2 0 -1 -1 0 -1 1 2 0 -1 2 -1 1 1 2 0 -1 2 0 0 1 1 0 0 0 2 2 1 0 0 1 1
figure
imagesc(M)
colormap(cmi)
hcb = colorbar;
xt = hcb.Ticks;
tix = linspace(min(xt), max(xt), size(cmi,1)*2+1);
hcb.Ticks = tix;
hcb.TickLabels = cell(1,numel(tix));
hcb.TickLabels(2:2:numel(hcb.Ticks)) = compose('%2d',min(xt):max(xt));
hcb.TickLength = 0; % Set TickLength' To 0
.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by