Heatmap doesnt show empty rows or columns
15 ビュー (過去 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.
1 件のコメント
参考
カテゴリ
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!