简单的方法在gscatter中获得更明智的颜色 [英] Simple way to get more sensible colors in gscatter
问题描述
我正在寻找一种简单的方法来让 gscatter
选择更明智的颜色。
当你可以在下面的图片中看到,组3和4具有非常相似的颜色,这很难区分。
我使用绘制数据, gscatter(X(:,1),X(:,4),assigns,[],[])
。
我知道我可以使用 scatter
通过创建一个具有与我拥有的组数相同数量的颜色的colormap来手动获取更明智的颜色,但是如何获得更好的图例像gscatter产生没有在每个组循环?
那么,有一个简单的(R)方法获得更多的明智的颜色与 gscatter $
$ p
$ b $ p $第四个参数<$ c $> 第四个参数<$ c $>第四个参数<$ c $> 第四个参数 gscatter
是颜色规格。根据文档,只能使用字母来定义颜色:
scatter(x,y,group,clr,sym,siz)
颜色,标记类型和每个组的大小。clr
是由plot
函数识别的颜色的字符串数组。clr
的默认值为'bgrcmyk'
。
但是,如果您键入打开gscatter
并查看第一行中的注释(Matlab的旧式帮助),惊喜!
GSCATTER(X,Y,G,CLR,SYM,SIZ)指定要使用的颜色,标记和
大小。 CLR是一串颜色规格或
a三列颜色规格矩阵。
所以你可以使用一个颜色映射矩阵来定义你想要的颜色(至少在Matlab R2014b中)。
例子:
载入判断
组(1:3:结束)= 3; %//借用Benoit_11的想法创建另外两个组
group(2:2:end)= 4;
cmap = hsv(4); %//在这里定义颜色映射
gscatter(评级(:1),评级(:2),组,cmap)
I'm looking for a simple way to get gscatter
to choose more sensible colors.
As you can see in the picture below, groups 3 and 4 have very similar colors, which are difficult to distinguish.
I'm plotting my data using gscatter(X(:,1),X(:,4),assigns , [], [] )
.
I know I can use scatter
to manually get more sensible colors by creating a colormap that has the same number of colors as the number of groups I have, but then how do I get a nice legend like gscatter produces without looping over each group?
So, is there a simple(r) way to get more sensible colors with gscatter
?
Thanks.
The fourth argument of gscatter
is the color specification. According to the documentation, only letters can be used to define the colors:
scatter(x,y,group,clr,sym,siz)
specifies the color, marker type, and size for each group.clr
is a string array of colors recognized by theplot
function. The default forclr
is'bgrcmyk'
.
But if you type open gscatter
and look at the comments in the first lines (Matlab's old-style help), surprise!
GSCATTER(X,Y,G,CLR,SYM,SIZ) specifies the colors, markers, and
size to use. CLR is either a string of color specifications or
a three-column matrix of color specifications.
So you can use a colormap matrix to define the colors you want (at least in Matlab R2014b).
Example:
load discrim
group(1:3:end) = 3; %// borrowing Benoit_11's idea to create two more groups
group(2:2:end) = 4;
cmap = hsv(4); %// define your colormap here
gscatter(ratings(:,1), ratings(:,2), group, cmap)
这篇关于简单的方法在gscatter中获得更明智的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!