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

Sug*_*kie 1 matlab plot matrix 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
Run Code Online (Sandbox Code Playgroud)

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

the*_*alk 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)
Run Code Online (Sandbox Code Playgroud)

然后,您可以应用您想要的任何色彩映射创建自己的色彩映射.

colormap(jet)
colorbar
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


如果你不喜欢imagescNaN考虑使用的句柄pcolor

pcolor(A)
colormap(jet)
colorbar
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

shading flat您可以摆脱网格线.