Some examples plots that seaborn can create, if everything goes well

Three common seaborn difficulties

Explaining some aspects of using seaborn that most often confound newcomers

You (might) need to reformat your data

A “messy” data table
A “messy” table representing a household budget.
A “tidy” data table, in long-form
The same budget, but represented in a “tidy” long-form table.
budget_long = budget.melt(
id_vars="Category",
var_name="Year",
value_name="Expense",
)
The rules that lineplot and boxplot use for wide-form data
There are many options for passing wide-form data, but different functions will interpret it differently.

There are two kinds of plotting functions

plt.plot(x, y)  # Plots on the "current" axes, creating it if needed
f, axs = plt.subplots(ncols=2) # Creates a new figure with two axes
axs[0].plot(x, y) # Plots on the first axes of the new figure
plt.plot(x, y) # Plots on the second axes of the new figure
sns.lineplot(x=x, y=y)  # Plots on the "current" axes
f, axs = plt.subplots(ncols=2) # Creates a new figure
sns.lineplot(x=x, y=y, ax=axs[0]) # Plots on the first new axes
sns.lineplot(x=x, y=y) # Plots on the second new axes
f, ax = plt.subplots()
sns.displot(data, x="a", ax=ax)
sns.displot(data, x="b", ax=ax)

Categorical plots will always be categorical

Sensible output from pointplot with a numeric x variable
Sometimes it makes sense to make treat a numeric variable as categorical…
Nonsensical output from pointplot with a numeric x variable
…but other times, it makes a huge mess.
Nonsensical output when layering a lineplot onto a stripplot
The stripplot treats size as categorical, but the lineplot doesn’t, so the line is shifted to the right.

--

--

Computational cognitive neuroscientist and creator of the seaborn data visualization library

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Waskom

Computational cognitive neuroscientist and creator of the seaborn data visualization library