Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a custom colour scheme in pandas/matplotlib/seaborn python

I want to use a custom colour scheme using for various plots but can't get it to work (using seaborn and/or matplob & pandas for these plots)

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

I get error code:

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

even

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

doesnt work

help please!

like image 508
pow Avatar asked Dec 18 '22 07:12

pow


2 Answers

Let's try this.

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")

With some other data here are the results.

enter image description here

like image 110
Scott Boston Avatar answered Dec 20 '22 20:12

Scott Boston


You need to set colours via palettes in Seaborn or you can pass Violinplot the colours directly via the 'palette' parameter rather than 'color'. It's all in the Seaborn docs.

like image 45
DrBenway Avatar answered Dec 20 '22 22:12

DrBenway