Heatmap doesnt show empty rows or columns
조회 수: 19 (최근 30일)
이전 댓글 표시
I have binned Data, one time vector and one data vector.
If I want to make a heatmap of this data, where i can see the instances of each bin over 24 hours. In my example, a bin is 2 hours on the x axis.
The heatmap doesnt plot rows or columns where no data is available, as seen below. The Rows 10 and twelve are missing.
Here is my code:
n_bins = 12;
t = table(Var1Discrete,Var2Discrete,'VariableNames',[Var1Name, Var2Name]);
hm = heatmap(t,Var1Name, Var2Name);
hm.MissingDataColor = [0,0,0];
hm.MissingDataLabel = 'NaN';
hm.GridVisible = false;
hm.XDisplayLabels = E1(1:n_bins);
hm.YDisplayLabels = E2(1:n_bins);
hm.ColorScaling = ColorScaling;
matlab also ignores the MissingDataColor and -Label.
As Rows are missing, it doesnt label the Y-Data, but numbers the different bins. I get the error:
Error using matlab.graphics.chart.HeatmapChart/set.YDisplayLabels
'YDisplayLabels' vector must contain the same number of elements as the 'YDisplayData' vector
How can I fix this?
댓글 수: 0
답변 (2개)
Adam Danz
2022년 11월 14일
By empty I assume you mean that there are NaN values present and I see that you are setting a missing data value color and label which would be consistent with that assumption.
Heatmap does indicate NaNs.
x = magic(12);
x(:,4) = nan;
x(4,:) = nan;
figure()
heatmap(x)
The error you're seeing is likely due to an indexing problem in
hm.YDisplayLabels = E2(1:n_bins);
But since we do not have access to E2 and n_bins, I can't be more specific.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!