简体   繁体   中英

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. In label , I have 4 categories - 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.

(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 ).

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:

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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM