使用网格中的colormap可视化矩阵

时间:2015-03-19 18:56:05

标签: matlab matrix plot imshow

我有一个看起来像这样的矩阵:

0.06    -0.22   -0.10   0.68    NaN     -0.33
0.04    -0.07   0.12    0.23    NaN     -0.47
NaN     NaN     NaN     NaN     NaN     0.28
0.37    0.36    0.14    0.58    -0.14   -0.15
NaN     0.11    0.24    0.71    -0.13   NaN
0.57    0.53    0.41    0.65    -0.43   0.03

我想根据色彩图在每个值中着色。在Python中,我知道我可以使用imshow为每个框分配颜色。我怎么能在MATLAB中做到这一点?

1 个答案:

答案 0 :(得分:5)

您也可以使用imshow,但每个像素的大小都是屏幕的像素。所以你可能宁愿使用imagesc

A =  [...
0.06    -0.22   -0.10   0.68    NaN     -0.33;
0.04    -0.07   0.12    0.23    NaN     -0.47;
NaN     NaN     NaN     NaN     NaN     0.28;
0.37    0.36    0.14    0.58    -0.14   -0.15;
NaN     0.11    0.24    0.71    -0.13   NaN;
0.57    0.53    0.41    0.65    -0.43   0.03 ]

imagesc(A)

然后您可以应用您想要的任何colormapcreate your own one

colormap(jet)
colorbar

enter image description here


如果您不喜欢imagesc处理NaN的方式,请考虑使用pcolor

pcolor(A)
colormap(jet)
colorbar

enter image description here

shading flat你可以摆脱网格线。

相关问题