Sometimes heatmap does not display decimal values

I have data sets representing pressures. These are represented by a matrix of 16 x 16 x 400(ish), representing a time pressure sequence of 400 temporally-ordered frames of a 16 x 16 array of 256 pressure sensors. I wanted to display the time maximum (using heatmap()) for each pressure sensor, and that worked exactly as expected. I display two alternative data sets side by side (using subplot), and get theit color-mapped squares with values, as expected. If instead I look at the temporal average, I only get the color mapped squares without the the decimal values.
If I insert a breakpoint, and issue:
heatmap(peaks1); colormap default
or
heatmap(av1); colormap default
both work as expected, but the following code:
f=figure;
f.Position = [0 128 1920 1280];
peaks1 = max(p_seq1, [], 3);
peaks2 = max(p_seq2, [], 3);
av1 = mean(p_seq1, 3);
a2 = mean(p_seq2, 3);
subplot(1,2,1);
% heatmap(av1);
heatmap(peaks1); % displays text correctly
colormap default
title([gait, ' - ', horse, ' (OS)']);
subplot(1,2,2);
heatmap(av2); % displays no text
% heatmap(peaks2);
colormap default ;
title([gait, ' - ', horse, ' (EQ)']);
filename = [horse, ' - ', gait, '.jpg']
saveas(f, filename);
doesn't display text for the av1 heatmap.
To further confuse things, one out of the 20 or so datasets I am using does display the average values, but I have no idea why.
Both the av and the peak show in the workspace as 16x16 double.
Thoughts?

댓글 수: 4

hello
can you share some of the data that create the issue ?
also I notice that you want to display av2 but you compute a2 so I wonder if av2 is actually defined
a2 = mean(p_seq2, 3);
heatmap(av2); % displays no text
Peter Fraser
Peter Fraser 2021년 10월 14일
편집: Peter Fraser 2021년 10월 14일
Sorry Mathieu, the "a2" was just sloppy editing by me. The actual code has "av2". I think that I have worked out what's going on. The averaged data typically have three more digits than the peak data (being averaged over ~400 samples). heatmap() wants to display all of these, reducing the size of the typeface to do so. If it considers the typeface too small to display, it just silently decides to not display anything.
If I use:
heatmap(round(av2 * 10)/10);
I get the result I want.
Thanks
at least problem solved !!
Yes! I first tried the multiply-round-divide trick in the command window, and it didn't work (it gives four places after the decimal point, with the last three "zero". Fortunately it does work with heatmap.

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

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2026년 1월 6일

0 개 추천

@Peter Fraser: The text in the cells in a heatmap hide themselves automatically when they get "too small". If you don't specify a FontSize, heatmap will look at the size of each cell and the size of the text that needs to be displayed, and calculate the FontSize necessary to fit the text into the cell. If that calculated FontSize is smaller than 6pt, then the labels are hidden.
There is no way to directly disable this behavior, or control the "minimum font size", but there is a workaround, which is to set the FontSize. By specifying the FontSize you disable both the automatic calculation of the FontSize as well as the automatic decision of whether to hide the text or not.

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 10월 14일

답변:

2026년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by