Visualize matrix with colormap in grid

自闭症网瘾萝莉.ら 提交于 2019-12-11 10:56:06

问题


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

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?


回答1:


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


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

pcolor(A)
colormap(jet)
colorbar

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



来源:https://stackoverflow.com/questions/29152793/visualize-matrix-with-colormap-in-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!