2016-04-11 157 views
1

有沒有辦法在調用Seaborn的factorplot時獲取分配給每個組的顏色?例如。我可以在以下圖表中獲得"one"的顏色嗎?謝謝!Seaborn:從factorplot/facetgrid獲取顏色/色調

df = pd.DataFrame({ 
    "name": ["one"]*4 + ["two"]*4 + ["three"]*4 + ["four"]*4 + ["five"]*4, 
    "value": np.random.randint(0, 10, 20), 
    "num": range(0, 4)*5 
    }) 
ax = sns.factorplot(x="num", y="value", hue="name", data=df, kind="point", legend_out=False) 
legend = plt.legend(fontsize="x-large") 
plt.show() 

plot

+0

不是試圖從圖中獲取顏色,而是指定想要繪製的顏色。 – mwaskom

+0

謝謝@mwaskom,我該怎麼做呢?我能說一些像「{」one「:」green「,」two「:」blue「}等,並將其傳遞給'hue'嗎? – Plasma

+0

是的,這將是一種方法。 – mwaskom

回答

0

是你想要的嗎?

In [84]: legend.parent.get_lines()[0].get_color() 
Out[84]: (0.2980392156862745, 0.4470588235294118, 0.6901960784313725) 
+0

這看起來很有前途,謝謝@MaxU!任何想法如何我可以提取例如'get_lines()'返回的列表中的「one」?而FWIW,我也不明白提問的提示。 – Plasma