Getting different colors for different numbers using `spy` in Matlab

断了今生、忘了曾经 提交于 2020-01-02 07:29:09

问题


When I use spy to check a sparsity pattern, it doesn't distinguish certain elements from others. Is there any way to do this? Say, for example, elements that are equal to 10 are red and all elements equal to 9 are blue. Can I get this in one spy plot?

I've only been able to change the size and style of the plot points.


回答1:


Here is how you can do it:

spy(a,'k')
hold on
spy(a==10,'r')
spy(a==9,'b')
hold off

Another way is to use scatter instead of spy :

[x,y] = find(a);
clr = a(a~=0);
scatter(x,y,[],clr)
set(gca,'YDir','rev')

In this case the points will be colored by a values according to current figure colormap.



来源:https://stackoverflow.com/questions/15838900/getting-different-colors-for-different-numbers-using-spy-in-matlab

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