2017-04-27 91 views
1

我想用各種陰謀使用自定義配色方案,但不能讓它的工作(使用seaborn和/或matplob &大熊貓爲這些地塊)使用熊貓/ matplotlib/seaborn蟒蛇自定義顏色方案

flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"] 
ax = sns.violinplot(x="Contents", y="Flavour", data=rd, color="lol", inner="box") 

我得到錯誤代碼:

ValueError: to_rgb: Invalid rgb arg "flatui" 
could not convert string to float: 'flatui' 

即使

ax = sns.violinplot(x="Contents", y="Flavour", data=rd, color=["9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"], inner="box") 

母鹿snt work

請幫忙!

+0

可能的重複[如何使用seaborns color \ _palette作爲matplotlib中的顏色映射?](http://stackoverflow.com/questions/37902459/how-do-i-use-seaborns-顏色調色板作爲一個顏色映射在matplotlib) – Serenity

回答

1

讓我們試試這個。

flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"] 
sns.set_palette(flatui) 
sns.palplot(sns.color_palette()) 

ax = sns.violinplot(x="Contents", y="Flavour", data=rd, color="lol", inner="box") 

這裏有一些其他的數據是結果。

enter image description here

+0

完美,謝謝! – mystifier

+0

我將如何去做這個只是一個matplotlib情節,如: grouped = rd.groupby([「數據包號碼」,「味道」])[「內容」]。sum()。unstack()。fillna (0) grouped.plot(kind =「bar」,stacked = True,colormap = [「#9b59b6」,「#3498db」,「#95a5a6」,「#e74c3c」,「#34495e」,「#2ecc71」 ]) 因爲這種方式不適用於您的建議 – mystifier

+0

grouped.plot grouped.plot(kind =「bar」,stacked = True,color = [「#9b59b6」,「#3498db」,「#95a5a6」,「#e74c3c」 ,「#34495e」,「#2ecc71」])是否有效? –

4

您需要設置通過調色板顏色Seaborn或者你可以直接通過「調色板」參數傳遞Violinplot的顏色,而不是「色」。這一切都在Seaborn docs.

+0

是的,用調色板也嘗試過,只是用顏色作爲解決問題的一種方法,最初既沒有工作 – mystifier