A concise guide to Seaborn for creating attractive and informative statistical graphics in Python.
Installation
pip install seaborn
Importing Seaborn
import seaborn as sns
import matplotlib.pyplot as plt
1. Relational Plots
Function: sns.relplot()
Creates scatter or line plots to show relationships between variables.
- Example: Scatter Plot
sns.relplot(data=tips, x="total_bill", y="tip", hue="time", kind="scatter")
- Example: Line Plot
sns.relplot(data=tips, x="size", y="tip", kind="line", hue="day", style="time")
Common Attribute for Relational Plots
2. Distribution Plots
Function: sns.displot()
Visualizes distributions with histograms, KDEs, rugs, or ECDFs.
- Histogram Example
sns.displot(data=penguins, x="flipper_length_mm", kind="hist", bins=20)
- KDE Plot Example
sns.displot(data=penguins, x="flipper_length_mm", kind="kde", fill=True)
Common Attribute for Distribution Plots
3. Categorical Plots
Function: sns.catplot()
Visualizes categorical data using multiple plot types.
- Example: Bar Plot
sns.catplot(data=tips, x="day", y="total_bill", kind="bar", hue="sex")
- Example: Violin Plot
sns.catplot(data=tips, x="day", y="total_bill", kind="violin", split=True, hue="sex")
Common Attribute for Categorical Plots
4. Color Palettes (palette)
Custom Palettes
- HUSL Palette:
sns.color_palette("husl", n_colors=8)
- CUBEHELIX Palette:
sns.color_palette("cubehelix", n_colors=8)
- Custom HEX Colors: [
"#4c72b0"
,"#55a868"
,"#c44e52"
] - Blend Two Colors:
sns.blend_palette(["red", "blue"], n_colors=8)
Top comments (0)