Quick Success Data Science

Have you started using the new Seaborn Objects System for plotting with Python? You definitely should; it’s a wonderful thing.
Introduced in late 2022, the new system is based on the Grammar of Graphics paradigm that powers Tableau and R’s ggplot2. This makes it more flexible, modular, and intuitive. Plotting with Python has never been better.
In this Quick Success Data Science project, you’ll get a quick start tutorial on the basics of the new system. You’ll also get several useful cheat sheets compiled from the Seaborn Objects official docs.
Installing Libraries
We’ll use the following open-source libraries for this project: pandas, Matplotlib, and seaborn. You can find installation instructions in each of the previous hyperlinks. I recommend installing these in a virtual environment or, if you’re an Anaconda user, in a conda environment dedicated to this project.
The New Seaborn Objects Interface
The goal of Seaborn has always been to make Matplotlib – Python’s primary plotting library – both easier to use and nicer to look at. As part of this, Seaborn has relied on declarative plotting, where much of the plotting code is abstracted away.
The new system is designed to be even more intuitive and to rely less on difficult Matplotlib syntax. Plots are built incrementally, using interchangeable marker types. This reduces the number of things you need to remember while allowing for a logical, repeatable workflow.
Everything Starts with Plot()
The use of a modular approach means you don’t need to remember a dozen or more method names – like barplot()
or scatterplot()
– to build plots. Every plot is now initiated with a single Plot()
class.

The Plot()
class sets up the blank canvas for your graphic. Enter the following code to see an example (shown using JupyterLab):
import seaborn.objects as so
so.Plot()

Plot()
with no arguments yields an empty figure (by the author)At this point, we don’t have any data, so let’s use Seaborn’s built-in open-source tips dataset, which records restaurant data such as the total bill, the tip amount, the day of the week, the party size, and so on. Here’s how to load it as a pandas DataFrame:
import pandas as pd
import seaborn as sns
# Load the tips dataset:
tips = sns.load_dataset('tips')
tips.head(3)

Now we can point Plot()
to the data and assign values for the x and y axes. As you might expect, the Seaborn Objects interface, like Seaborn, works very well with pandas DataFrames.
so.Plot(data=tips, x="total_bill", y="tip")

This isn’t much better than the previous plot but note the x and y axes. The plot is "aware" of the underlying data. Now all we need to do is inform Plot()
of the type of plot we want by specifying a mark
. This is more intuitive than having to call a dedicated method for a plot type.
fig = so.Plot(data=tips, x='total_bill', y='tip').add(so.Dot(), color='sex')
# fig.show()

Here, we incrementally built the plot by first initiating it with a call to Plot()
and then adding the dot markers with a call to Dot()
. Since, intuitively, dots are used with scatterplots, this produced a scatterplot!
At this point, you’ve used the basic (and required) syntax for building a plot with the new system:
- A call to
Plot()
, - Assignment of a
data
argument, - Assignment of a coordinate argument (such as
x
and/ory
), - A call to the
add()
method to add a layer to the plot, - A call to a method inside
add()
to specify the marker/plot type.
Here’s how it looks in its most basic form:
so.Plot(data=tips, x='total_bill', y='tip').add(so.Dot())
Note that, while you have to pass some mark to the add()
method, it doesn’t have to be Dot()
. We’ll look at other options shortly.
Plot() Methods
The Plot()
class comes with over a dozen methods that let you add marks, scale data, create faceted or paired subplots, control figure dimensions, share labels between subplots, save plots, and so on. These are summarized from the official docs in the table below.

These methods are called using dot notation. Here’s the full syntax (assuming no aliases are used when importing):
seaborn.objects.Plot.add()
Using Parentheses for Readability
With Seaborn Objects, we build plots by chaining multiple methods using dot notation. This can cause the code to become a bit unreadable. To alleviate this, it’s best to enclose the plotting code in parentheses. This way, we can call each new method on a separate line. Here’s an example where we add a regression line and a title:
fig = (so.Plot(data=tips, x='total_bill', y='tip')
.add(so.Dot(), color='sex')
.add(so.Line(color='red'), so.PolyFit())
.label(title='Tips vs. Bill'))
fig.show()

We layered in the regression line by invoking the add()
method again with the Line()
and PolyFit()
classes. Then we used the Plot()
class’s label()
method to add a title. By surrounding the whole plotting code with parentheses, each of these class and method calls can be displayed on a single line, making them easy to find.
NOTE: If you’re familiar with Seaborn, then you know that the "old" system’s
regplot()
method automatically added the 95% confidence interval band to the regression line (see Declarative vs. Imperative Plotting). This feature has not yet been implemented in the new system, so not everything is better!
Seaborn Objects System Classes
The new system includes over two dozen classes for creating plots, adding marker types, drawing error bars and ranges, adding text, aggregating values, shifting over-posted points, and more. These are summarized from the official docs in the table below.

For more details and to see example plots, visit the docs. For details on styling the marker types, see "Properties of Mark Objects."
Creating Facet Grids
The new system is excellent at preparing multi-panel plots, like facet grids and pair plots. A facet grid is a multi-plot grid. It allows you to subset data and compare (visualize) the subsets using columns of plots with comparable data ranges.
To create facet grids with Seaborn Objects, you use a method of the Plot()
class, as so:
fig = (so.Plot(tips, 'total_bill', 'tip')
.add(so.Dot(), color='sex')
.add(so.Line(color='red'), so.PolyFit()))
fig.facet("sex")

We’ve now "pulled apart" our previous figure so that the male and female data points aren’t jumbled together. This makes it easier to see trends and limits in each conditional dataset.
Like any declarative plotting system, Seaborn Objects is designed to abstract away much of the overhead required for making common plots, but this can result in some loss of flexibility. In addition, the system is still under development. This means that some tasks aren’t as straightforward as they are in the old system.
For example, to add a "super" title across the top of a facet grid, you have to rely on Matplotlib’s pyplot
module. First, you import it and use it to instantiate the figure (fig
), then you call the old suptitle()
method to enter the title.
After that, you use the new Plot()
class’s on(fig)
method to post the data "on" the figure. Here’s how it looks:
import matplotlib.pyplot as plt
fig = plt.Figure(figsize=(5, 6))
fig.suptitle("Tips vs. Total Bill by Gender")
(
so.Plot(tips, 'total_bill', 'tip')
.add(so.Dot(), color='sex')
.add(so.Line(color='red'), so.PolyFit())
.facet(col='sex')
.on(fig)
)

Creating Pair Plots
A pair plot, also called a scatterplot matrix, is a Data Visualization technique for comparing pairwise relationships between multiple variables in a dataset.
To make a pair plot with Seaborn Objects, you need to specify the dataset and values for the y-axis using Plot()
, then call the pair()
method to choose the x-axis columns from the DataFrame, then use the add()
method to specify the mark type, and whether you want to color the markers by the values in a column. Here’s an example:
(
so.Plot(tips, y='tip')
.pair(x=['total_bill', 'size', 'sex'])
.add(so.Dots(), color='sex')
)

Note that I use Dots()
, rather than Dot()
, for the markers. The goal is to improve the legibility of over-posted points by automatically using unfilled dots.
Bars and Counts
If you were performing exploratory analysis on the tips dataset, you’d probably want to know the breakout of male vs. female customers. This is a job for the Count()
and Bar()
classes. Notice again how using encompassing parentheses lets you structure the code for maximum readability:
(
so.Plot(tips, x='sex')
.add(so.Bar(),
so.Count(),
color='sex')
)

Looks like there are almost twice as many men as women in the dataset.
Summary
Just as Seaborn makes Matplotlib better, the Seaborn Objects System improves on Seaborn. Among the biggest changes is replacing the previous plotting methods with the Plot()
class, which serves as the "one ring to rule them all." Every figure is now initiated using Plot()
.
Previously, each plot type had a dedicated method, such as sns.barplot()
for bar charts and sns.scatterplot()
for scatterplots. To layer on more information, you often needed another, similar method, like sns.regplot()
(for regression lines). This made it difficult to declaratively build more intricate plots.
With the modular approach of Seaborn Objects, you can now use intuitive methods, like add()
, to layer on intuitively named markers, such as dots, lines, and bars. This "Grammar Of Graphics" approach lets you build up plots using a consistent, logical methodology.
The new system is designed for making quick, "standardized" plots using declarative plotting. For more complicated plots, you’ll still need to rely on imperative plotting with Matplotlib (once again, see Declarative vs. Imperative Plotting).
Finally, be aware that the new system isn’t fully built out. To quote the Seaborn docs: "The new interface is currently experimental and incomplete. It is stable enough for serious use, but there certainly are some rough edges and missing features."
Further Reading
Here are some additional references useful for grokking Seaborn Objects:
Anaconda: An Introduction to the Seaborn Objects System
Seaborn version 0.12.0 with ggplot2-like interface
Seaborn 0.12: An Insightful Guide to the Objects Interface and Declarative Graphics
A Quick Introduction to the Seaborn Objects System
Thanks!
Thanks for reading and please follow me for more Quick Success Data Science projects in the future.