使用网格中的颜色图可视化矩阵 [英] Visualize matrix with colormap in grid

查看:105
本文介绍了使用网格中的颜色图可视化矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a matrix that looks like this:

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

I want to color in each value based on a colormap. In Python, I know I can use imshow to assign a color to each box. How can I do it in MATLAB?

推荐答案

您可以使用 imagesc .

You could use 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)

然后您可以应用任何 颜色图 > 创建自己的 .

And then you can apply any colormap you want or create your own one.

colormap(jet)
colorbar

如果您不喜欢imagesc如何处理NaN,请考虑使用

If you don't like how imagesc handles your NaNs consider using pcolor

pcolor(A)
colormap(jet)
colorbar

使用shading flat,您可以摆脱网格线.

with shading flat you can get rid of the grid lines.

这篇关于使用网格中的颜色图可视化矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆