필터 지우기
필터 지우기

Edit colorbar of heatmap (string)

조회 수: 158 (최근 30일)
Gerrit Liedtke
Gerrit Liedtke 2019년 6월 26일
답변: Tony Castillo 2023년 12월 19일
Hi,
Is it possible to edit the colorbar of a heatmap such that it looks like the following image (rapidly created with paint ;) )
a.PNG
So the values aren't numeric but strings.
Thanks for help!
  댓글 수: 1
Adam Danz
Adam Danz 2019년 6월 26일
편집: Adam Danz 2019년 6월 28일
The handle to the colorbar in heatmap is inaccessible. Without the handle, you can't change properties to the colorbar; you can't even delete it. Even when you try to add a new colorbar, you cannot output the handle with a heatmap plot.
heatmap() in general is highly restrictive in the user's abilty to manipulate many of its properties. I used to use heatmap more frequently prior to these changes and have moved onto using imagesc() instead. Bummer.

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

채택된 답변

Adam Danz
Adam Danz 2019년 6월 26일
편집: Adam Danz 2019년 6월 27일
This can't be done with heatmap() (see comments under the question).
If you're using a different function that allows access to the colobar, it's fairly straightforward. Here's a demo.
% Create demo
C = rand(3,4)/10;
imagesc(C)
cbh = colorbar();
% set color range
caxis([0,.1])
% set ticks
set(cbh, 'YTick', [0.001, 0.01, 0.05, .1], ...
'YTickLabel', {'p=0.001', 'p=0.01', 'p=0.05', 'p=.1'})

추가 답변 (2개)

Christian Karcher
Christian Karcher 2020년 4월 28일
편집: Christian Karcher 2020년 4월 28일
The handle to the colorbar is accessible, and with it all modifications:
figure;
heatmap(rand(5))
axs = struct(gca); %ignore warning that this should be avoided
cb = axs.Colorbar;
cb.TickLabels = {'p<0.1','p>0.1','...'};
  댓글 수: 7
Alexander Krauss
Alexander Krauss 2022년 9월 29일
편집: Alexander Krauss 2022년 9월 29일
Great solution, thanks a lot (also for the rapid reply) ! :)
Best regards,
Alex
Muhanned Alsaif
Muhanned Alsaif 2023년 8월 21일
편집: Muhanned Alsaif 2023년 8월 21일
another way to access the colorbar can be found in the following post:

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


Tony Castillo
Tony Castillo 2023년 12월 19일
Is it possible to add a label to that colour bar which is directly created in a heatmap? I mean we can tag a SURF plot (the colourbar because it is separated from the surfplot), but I have not found the manner of doing the same in the colorbar of the heatmap.

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by