![](/img/trans.png)
[英]How can I change the colors of a chart's data points depending on the value of the Y-axis? (Python: Matplotlib)
[英]How to change colors of points in Python's ggplot
我試圖弄清楚如何更改ggplot在我的繪圖上產生的顏色。 在label
,我有4個類別- 0
, 1
, 2
, 3
。 當前,ggplot將這些顏色分別設置為紫色,綠色和紅色,但我想將其更改為藍色陰影(0除外)。為了說明這一點,如果我的熊貓數據框中的標簽為0
,則我希望它只是一個灰色的點,如果它的標記1
,淡藍色的,如果它是2
,藍蔭正常,如果是3
,然后是深藍色的。
(如果您想知道為什么它只使用紅色,綠色和紫色,是因為對於我當前的數據集,標簽2
都沒有點)。
到目前為止,這就是我所擁有的:
gg = ggplot(aes('index', 'clicks', color = 'label'), data=xy_data) + \
geom_point() +\
xlab("Date") + ylab("Total clicks")
print gg
需要更改什么?
您可以使用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
默認情況下,scale_fill_brewer()顯示不同的藍色陰影,但是也可以通過在scale_fill_brewer()中使用調色板參數來使用不同的陰影。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.