Nearly every seaborn call takes data= plus column names; getting the data shape right is most of the work.
seaborn is a layer over Matplotlib: you describe what to show in terms of DataFrame columns, and it computes statistics, picks colors, builds the legend and draws with Matplotlib. The convention is import seaborn as sns.
The typical call looks like sns.scatterplot(data=df, x="height", y="weight", hue="sex"). Each keyword assigns a column to a semantic role: position (x, y), color (hue), marker style, size, or a facet (col, row).
seaborn works best with long-form (tidy) data: one row per observation, one column per variable. A table with a year column, a city column and a sales column is long-form. A table with one column per city is wide-form. Many functions accept wide-form too (each column becomes a series), but long-form is what lets you map any variable to any role. Convert with df.melt(id_vars=..., var_name=..., value_name=...).
sns.load_dataset("tips") fetches small example datasets used throughout the documentation. It downloads from the internet, so in offline code build your own DataFrame.
seaborn functions return the Matplotlib object they drew on (an Axes, or a grid object), so titles, limits and saving all work as in Matplotlib. Save through the figure: ax.figure.savefig("plot.png").
When a column contains numbers, seaborn treats it as numeric (continuous color scale, numeric axis); strings and pandas categoricals are treated as categories with distinct colors.
Example
import matplotlib
matplotlib.use("Agg")
import seaborn as sns
import pandas as pd
wide = pd.DataFrame({"year": [2024, 2025, 2026],
"Paris": [10, 12, 15], "Lyon": [7, 9, 8]})
long = wide.melt(id_vars="year", var_name="city", value_name="sales")
print(long.shape) # (6, 3)
print(long.columns.tolist()) # ['year', 'city', 'sales']
ax = sns.lineplot(data=long, x="year", y="sales", hue="city", marker="o")
ax.set_title("Sales by city")
print(type(ax).__name__) # Axes
print([t.get_text() for t in ax.get_legend().get_texts()]) # ['Paris', 'Lyon']
ax.figure.savefig("sales.png")Remember
- Pass
data=dfand assign columns to roles: x, y, hue, style, size, col, row - Prefer long-form data; reshape wide tables with
melt - Functions return Matplotlib objects you can keep customizing
Watch out for
- Passing a wide table and expecting
hue=to refer to its column names, which only exist as headers, not as a variable.