Customizing boxplots appearance with Seaborn

logo of a chart:Box1

This post aims to describe 3 different customization tasks that you may want to apply to a Seaborn boxplot.

Custom linewidth

Customizing your boxplot's linewidth is really straightforward and quickly done through the 'linewidth' argument.

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

sns.boxplot(x=df["species"], y=df["sepal_length"], linewidth=5)
plt.show()

Add notch

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

sns.boxplot(x=df["species"], y=df["sepal_length"], notch=True)
plt.show()

Controlling box size

This can be an interesting modification in the case where you are facing with multiple categories to display in the same figure, given that space is limited.

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

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

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    dataviz decision tree poster