How to customize Colorbar in heatmap?

조회 수: 32 (최근 30일)
heejin choi
heejin choi 2024년 1월 16일
댓글: heejin choi 2024년 1월 16일
I want to change the colorbar ticks and labels.
But in updated heatmap function, the colorbar is not output object of heatmap function.
How can I change the colorbar ticks and label?
In attached figure, I want to change colorbar that has ticks only 0 and 1 and each label will be "No" and "Yes", respectively.
mon_label = ["Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"];
figure(555)
h = heatmap(scedata,'CellLabelColor','none');
Ax = gca;
Ax.XDisplayLabels = mon_label;

채택된 답변

Angelo Yeo
Angelo Yeo 2024년 1월 16일
Try something like this. Using struct can reveal hidden properties like "Colorbar".
cdata = [1, 0, 0; 0, 1, 0; 0, 0, 1];
h = heatmap(cdata);
colormap([h.Colormap(1,:); h.Colormap(end,:)]);
hs = struct(h);
Warning: Calling STRUCT on an object prevents the object from hiding its implementation details and should thus be avoided. Use DISP or DISPLAY to see the visible public details of an object. See 'help struct' for more information.
hs.Colorbar.Ticks = [0.25, 0.75];
hs.Colorbar.TickLabels = {'False', 'True'};
  댓글 수: 1
heejin choi
heejin choi 2024년 1월 16일
Thank you very much!! You solve my problem! I don't know about struct function.
Thank you for your kindly helps. :)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by