Seaborn
Seaborn is a high-level Python library for creating statistical graphics, building on Matplotlib and integrating closely with Pandas data structures. It provides a dataset-oriented API to draw attractive and informative statistical plots with ease. The library is actively maintained with regular minor and major releases, currently at version 0.13.2, ensuring compatibility with evolving data science ecosystems.
Warnings
- breaking The `seaborn.objects` interface was introduced in v0.12.0, offering a new declarative API. While powerful, it's considered experimental and may have breaking changes or rough edges in early minor releases.
- breaking Seaborn's categorical plotting functions (e.g., `boxplot`, `barplot`, `catplot`) underwent a major overhaul in v0.13.0. This includes changes to color defaults (now requiring explicit `hue` for multiple colors) and the introduction of the `native_scale` parameter.
- deprecated Python 3.7 support was dropped in Seaborn v0.12.2.
- gotcha Positional arguments for most plotting functions were deprecated in v0.11.0 and enforced to be keyword-only in v0.12.0. This applies to arguments like `x`, `y`, `hue`, etc.
- gotcha A regression in v0.13.0 caused exceptions when working with non-NumPy data types (e.g., Pandas nullable dtypes), which was fixed in v0.13.1. Pandas dtypes can still sometimes cause issues as Matplotlib (and by extension, Seaborn) often expects NumPy dtypes.
- gotcha When combining categorical plots with other plot types (e.g., a bar plot and a line plot on the same axes), misalignment can occur because categorical plots internally map string/category values to integer indices.
Install
-
pip install seaborn
Imports
- seaborn
import seaborn as sns
- seaborn.objects
import seaborn.objects as so
Quickstart
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme(style="darkgrid")
# Load an example dataset
tips = sns.load_dataset("tips")
# Create a scatter plot
sns.scatterplot(
data=tips,
x="total_bill",
y="tip",
hue="smoker",
style="time",
size="size"
)
plt.title("Total Bill vs. Tip by Smoker and Time")
plt.xlabel("Total Bill ($)")
plt.ylabel("Tip ($)")
plt.show()