Plot matrix values as colors in a checkerboard pattern
5 ビュー (過去 30 日間)
古いコメントを表示
Hi
I have the following matrix
C = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
I would like to plot each value as a colored cell in a checkerboard pattern. The "-1" values are throwaway data, and should be marked by a red cell. The rest of the cells should have some color scale, so to be distinguishable from each other. Is this possible?
I tried using the suggestion by Cam in this answer, and it almost does what I want. However the negative values become purple, and the rest yellow. I'm guessing because the colorscale is applied to the range [-1,0.155], and all the actual data values are very close.

Regards
Søren
0 件のコメント
採用された回答
Tommy
2020 年 5 月 4 日
Why red? What if some real data is mapped to red?
You are right about the -1 values messing things up. But the 0s on the border (from the answer in your link) also mess things up.
You could replace all -1s with NaN and pad with NaNs instead of 0s:
C0 = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
C = C0;
C(C == -1) = NaN;
C = [[C nan(size(C,1),1)] ; nan(1,size(C,2)+1)];
pcolor(C)
This leaves the -1 squares completely blank. One way to set them to red would be to color the underlying axes to red:
C0 = [-1 -1 0.155;
0.150 -1 0.152;
0.140 0.143 0.148];
C = C0;
C(C == -1) = NaN;
C = [[C nan(size(C,1),1)] ; nan(1,size(C,2)+1)];
ax = axes;
pcolor(ax, C)
ax.Color = 'r';
その他の回答 (0 件)
参考
カテゴリ
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!