Benjamin Nguyen
Benjamin Nguyen

Reputation: 177

set color for each violin in violin plot

I tried violin plot in Seaborn with different colors for each violin as:

sns.violinplot(x='type', y='den', data=mydf, ax=axes[0], color=['red','blue','yellow'])

however I got:

ValueError: to_rgb: Invalid rgb arg "('red', 'blue', 'yellow')" could not convert string to float: red

Upvotes: 7

Views: 10260

Answers (1)

Bart
Bart

Reputation: 10248

I think you should use the palette keyword:

color : matplotlib color, optional

Color for all of the elements, or seed for light_palette() when using hue nesting.

palette : seaborn color palette or dict, optional

Colors to use for the different levels of the hue variable. Should be something that can be interpreted by color_palette(), or a dictionary mapping hue levels to matplotlib colors.

import seaborn as sb
import numpy as np

data = np.random.random([100,4])

sb.violinplot(data=data, palette=['r','g','b','m'])

enter image description here

Upvotes: 12

Related Questions