Change line width

Depending on visual preferences, you may want to accentuate the distribution contour. This can be performed by setting the value of the linewidth parameter.

Custom seaborn violinplot: Change line width


# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
plt.rcParams['figure.dpi'] = 300
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')
 
# Change line width
sns.violinplot(x=df["species"], y=df["sepal_length"], linewidth=5)
plt.show()

Change the general width

In the case where you have multiple distributions to display on the same graph and you want to be sure that they do not overlap, you can also change the width parameter.

Custom seaborn violinplot: Change the general width

# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')

# Change width
sns.violinplot(x=df["species"], y=df["sepal_length"], width=0.3)
plt.show()

Empty violins

Thanks to the fill argument, we can easily remove the background of the violins:

Custom seaborn violinplot: Empty violins

# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')

# Change width
sns.violinplot(x=df["species"], y=df["sepal_length"], fill=False)
plt.show()

Saturation

A simple way to improve the style of a violin is to lower the saturation level (default 1):

Custom seaborn violinplot: Saturation

# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
  
sns.set_theme(style="darkgrid")
df = sns.load_dataset('iris')

# Change width
sns.violinplot(x=df["species"], y=df["sepal_length"], saturation=0.2)
plt.show()

Going further