问题
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