Back to Seaborn

Boxplot

doc/_docstrings/boxplot.ipynb

0.13.21.0 KB
Original Source
python
import seaborn as sns
sns.set_theme(style="whitegrid")
titanic = sns.load_dataset("titanic")
python
sns.boxplot(x=titanic["age"])
python
sns.boxplot(data=titanic, x="age", y="class")
python
sns.boxplot(data=titanic, x="class", y="age", hue="alive")
python
sns.boxplot(data=titanic, x="class", y="age", hue="alive", fill=False, gap=.1)
python
sns.boxplot(data=titanic, x="age", y="deck", whis=(0, 100))
python
sns.boxplot(data=titanic, x="age", y="deck", width=.5)
python
sns.boxplot(data=titanic, x="age", y="deck", color=".8", linecolor="#137", linewidth=.75)

Group by a numeric variable and preserve its native scaling:

python
ax = sns.boxplot(x=titanic["age"].round(-1), y=titanic["fare"], native_scale=True)
ax.axvline(25, color=".3", dashes=(2, 2))
python
sns.boxplot(
    data=titanic, x="age", y="class",
    notch=True, showcaps=False,
    flierprops={"marker": "x"},
    boxprops={"facecolor": (.3, .5, .7, .5)},
    medianprops={"color": "r", "linewidth": 2},
)