[英]How to change colors of points in Python's ggplot
I'm trying to figure out how to change the colors that ggplot produces on my plot. 我试图弄清楚如何更改ggplot在我的绘图上产生的颜色。 In
label
, I have 4 categories - 0
, 1
, 2
, 3
. 在
label
,我有4个类别- 0
, 1
, 2
, 3
。 Currently ggplot colors these as purple, green, and red, but I would like to change it to shades of blue, with the exception of 0. To clarify, if for that point, the label in my pandas data frame is a 0
, then I want it to just be a gray colored point, if it's labeled 1
, a light blue, if it's 2
, normal shade of blue, and if it's 3
, then a dark blue. 当前,ggplot将这些颜色分别设置为紫色,绿色和红色,但我想将其更改为蓝色阴影(0除外)。为了说明这一点,如果我的熊猫数据框中的标签为
0
,则我希望它只是一个灰色的点,如果它的标记1
,淡蓝色的,如果它是2
,蓝荫正常,如果是3
,然后是深蓝色的。
(In case you're wondering why it only uses red, green, and purple, is because for my current data set, there are no points with the label 2
). (如果您想知道为什么它只使用红色,绿色和紫色,是因为对于我当前的数据集,标签
2
都没有点)。
So far this is what I have: 到目前为止,这就是我所拥有的:
gg = ggplot(aes('index', 'clicks', color = 'label'), data=xy_data) + \
geom_point() +\
xlab("Date") + ylab("Total clicks")
print gg
What needs to be changed? 需要更改什么?
You could use the scale_fill_brewer function: 您可以使用scale_fill_brewer函数:
gg = ggplot(aes('index', 'clicks', color = 'label'), data=xy_data) + \
geom_point() +\
ggplot.scale_fill_brewer() +\
xlab("Date") + ylab("Total clicks")
print gg
By default scale_fill_brewer() displays different shades of blue but you can use different shades too by using palette argument inside scale_fill_brewer(). 默认情况下,scale_fill_brewer()显示不同的蓝色阴影,但是也可以通过在scale_fill_brewer()中使用调色板参数来使用不同的阴影。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.