在网格中使用颜色图可视化矩阵

Visualize matrix with colormap in grid

我有一个如下所示的矩阵:

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 中完成?

你可以使用 imshow as well, but every pixel would have the size of a pixel of your screen. So you may rather use 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)

然后您可以应用任何 colormap you want or create your own one

colormap(jet)
colorbar


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

pcolor(A)
colormap(jet)
colorbar

shading flat 你可以去掉网格线。