DEV Community

Cover image for Seaborn Cheat Sheet
Arum Puri
Arum Puri

Posted on

1

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay