arum_puripratamawati_ef5

Arum Puri

Posted on November 30, 2024

Seaborn Cheat Sheet

A concise guide to Seaborn for creating attractive and informative statistical graphics in Python.

Installation

pip install seaborn

Enter fullscreen mode Exit fullscreen mode

Importing Seaborn

import seaborn as sns
import matplotlib.pyplot as plt

Enter fullscreen mode Exit fullscreen mode

1. Relational Plots

Function: sns.relplot()

Creates scatter or line plots to show relationships between variables.

Image description

- Example: Scatter Plot

sns.relplot(data=tips, x="total_bill", y="tip", hue="time", kind="scatter")

Enter fullscreen mode Exit fullscreen mode

- Example: Line Plot

sns.relplot(data=tips, x="size", y="tip", kind="line", hue="day", style="time")

Enter fullscreen mode Exit fullscreen mode

Common Attribute for Relational Plots
Image description


2. Distribution Plots

Function: sns.displot()

Visualizes distributions with histograms, KDEs, rugs, or ECDFs.

Image description

- Histogram Example

sns.displot(data=penguins, x="flipper_length_mm", kind="hist", bins=20)

Enter fullscreen mode Exit fullscreen mode

- KDE Plot Example

sns.displot(data=penguins, x="flipper_length_mm", kind="kde", fill=True)

Enter fullscreen mode Exit fullscreen mode

Common Attribute for Distribution Plots
Image description


3. Categorical Plots

Function: sns.catplot()

Visualizes categorical data using multiple plot types.

Image description

- Example: Bar Plot

sns.catplot(data=tips, x="day", y="total_bill", kind="bar", hue="sex")

Enter fullscreen mode Exit fullscreen mode

- Example: Violin Plot

sns.catplot(data=tips, x="day", y="total_bill", kind="violin", split=True, hue="sex")

Enter fullscreen mode Exit fullscreen mode

Common Attribute for Categorical Plots
Image description


4. Color Palettes (palette)

Image description

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)

Style Attributes

Image description


Advanced Distribution Attributes

Image description


Common Attributes for All Plots

Image description

💖 💪 🙅 🚩
arum_puripratamawati_ef5
Arum Puri

Posted on November 30, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Seaborn Cheat Sheet
seaborn Seaborn Cheat Sheet

November 30, 2024