在Matlab中使用`spy`为不同的数字获取不同的颜色 [英] Getting different colors for different numbers using `spy` in Matlab

查看:448
本文介绍了在Matlab中使用`spy`为不同的数字获取不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用间谍检查稀疏模式时,它无法将某些元素与其他元素区分开.有什么办法吗?举例来说,等于10的元素为红色,而等于9的所有元素为蓝色.我可以在一个spy图中得到它吗?

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.

推荐答案

以下是您的操作方法:

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


另一种方法是使用scatter而不是spy:


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')

在这种情况下,这些点将根据当前图形的颜色图以a值进行着色.

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

这篇关于在Matlab中使用`spy`为不同的数字获取不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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