4

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!

pow
  • 415
  • 3
  • 8
  • 18
  • Possible duplicate of [How do I use seaborns color\_palette as a colormap in matplotlib?](http://stackoverflow.com/questions/37902459/how-do-i-use-seaborns-color-palette-as-a-colormap-in-matplotlib) – Serenity Apr 27 '17 at 21:50

2 Answers2

7

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

Scott Boston
  • 147,308
  • 15
  • 139
  • 187
  • How would I go about doing this in just a matplotlib plot such as: grouped = rd.groupby(["Packet number", "Flavour"])["Contents"].sum().unstack().fillna(0) grouped.plot(kind="bar", stacked=True, colormap=["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]) as this way does not work with your suggestion – pow Apr 27 '17 at 15:55
  • grouped.plot(kind="bar", stacked=True, color=["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]) Does that work? – Scott Boston Apr 27 '17 at 15:58
4

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.

DrBenway
  • 121
  • 4
  • yep, tried with palette also, just used color as one way to fix the problem, neither worked initially – pow Apr 27 '17 at 13:49