Seaborn
Install packages
You can use both pip or astral/uv.
| !uv pip install -q \
pandas==2.3.2 \
pandas-stubs==2.3.2.250827 \
numpy==2.3.2 \
matplotlib==3.10.6 \
seaborn==0.13.2
|
Import packages
| import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
sns.set_style("darkgrid")
sns.set_theme(style="darkgrid")
|
Usage
Plots
Load tips dataset.
| tips = sns.load_dataset("tips")
tips.head()
|
|
total_bill |
tip |
sex |
smoker |
day |
time |
size |
0 |
16.99 |
1.01 |
Female |
No |
Sun |
Dinner |
2 |
1 |
10.34 |
1.66 |
Male |
No |
Sun |
Dinner |
3 |
2 |
21.01 |
3.50 |
Male |
No |
Sun |
Dinner |
3 |
3 |
23.68 |
3.31 |
Male |
No |
Sun |
Dinner |
2 |
4 |
24.59 |
3.61 |
Female |
No |
Sun |
Dinner |
4 |
Scatter Plot
| sns.scatterplot(x="total_bill", y="tip", data=tips, color="#F79E6B")
plt.title("Total bill x tips")
plt.show()
|
Line Plot
| sns.lineplot(x="size", y="total_bill", data=tips, color="#92A78C")
plt.title("Total bill by size")
plt.show()
|
Bar Plot
| sns.barplot(
x="day",
y="total_bill",
data=tips,
color="#F7CD82",
estimator=np.mean,
)
plt.title("Average bill per day")
plt.show()
|
Box Plot
| sns.boxplot(x="day", y="total_bill", data=tips, color="#E0D5AD")
plt.title("Total bill per day")
plt.show()
|
Violin Plot
| sns.violinplot(x="day", y="total_bill", data=tips, color="#F7CD82")
plt.title("Total bill per day")
plt.show()
|
Histogram Plot
| sns.histplot(tips["total_bill"].tolist(), bins=10, kde=True)
plt.show()
|
KDE Plot
| sns.kdeplot(tips["total_bill"].tolist(), fill=True)
plt.show()
|
Pair Plot
| sns.pairplot(tips)
plt.show()
|
Heat Map
| correlation = tips[["total_bill", "tip", "size"]].corr()
correlation
|
|
total_bill |
tip |
size |
total_bill |
1.000000 |
0.675734 |
0.598315 |
tip |
0.675734 |
1.000000 |
0.489299 |
size |
0.598315 |
0.489299 |
1.000000 |
| sns.heatmap(correlation, annot=True, cmap="coolwarm")
plt.show()
|
Customization
| plt.figure(figsize=(10, 5))
sns.barplot(
x="day",
y="total_bill",
data=tips,
color="#F7CD82",
estimator=sum,
)
plt.ylabel("Total bill")
plt.xlabel("Day")
plt.title("Total bills per day")
plt.show()
|