Plot matrix values as colors in a checkerboard pattern
2 次查看(过去 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!