• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

How To Make Scatterplot with marginal boxplots with Seaborn ?

datavizpyr · November 8, 2020 ·

Last updated on August 22, 2025

In this post, we will learn how to make a scatterplot with marginal boxplots using Seaborn in Python. To make a scatterplot we will use some of Seaborn’s powerful but not very well known functionalities. More specifically, we will use Seaborn’s JointGrid() to set up the plot features and then add two layers of plots. First we will add scatter plot and then we will add boxplot on the marginals.

First, let us load the libraries needed.

👉 Want more? Explore the full Seaborn Tutorial Hub with 35+ examples, code recipes, and best practices.

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

We will load Penguins data directly from the github.

penguins_data="https://raw.githubusercontent.com/datavizpyr/data/master/palmer_penguin_species.tsv"
penguins_df = pd.read_csv(penguins_data, sep="\t")
penguins_df.head()

Seaborn’s JointGrid help us create “Grid for drawing a bivariate plot with marginal univariate plots.”. It helps build layers of plot. At first, we will use JointGrid() with data and x and y-axis we want to use. This simply creates an empty plot as shown below.

# set plot context to set plot sizes 
sns.set_context("talk", font_scale=1.2)
plt.figure(figsize=(12,10))
g = sns.JointGrid(data=penguins_df, 
                  x="culmen_length_mm",
                  y="culmen_depth_mm")
Building Scatterplot with marginal boxplot Seaborn
Building Scatterplot with marginal boxplot Seaborn

Now we can add layers of plots over the JointGrid() plot. Here we use Seaborn’s plot_joint() function to make scatter plot. TO do that, we call Seaborn’s scatterplot() as argument to plot_joint().

g.plot_joint(sns.scatterplot)

Since we have already specified the data and x and y-axis using JointGrid(), it is enough to specify the scatterplot function name and this makes a simple scatterplot.

Building Scatterplot with marginal boxplot Seaborn plot_joint().
Building Scatterplot with marginal boxplot: Seaborn plot_joint().

We can then add the marginal boxplots using plot_marginals() function with Seaborn’s boxplot() function as argument.

g.plot_joint(sns.scatterplot)
g.plot_marginals(sns.boxplot)
plt.savefig("Scatterplot_with_marginal_boxplot_Seaborn.png",
                    format='png',dpi=150)

Now we get scatterplot with boxplot along the marginals with Seaborn.

Scatterplot with marginal boxplot with Seaborn
Scatterplot with marginal boxplot with Seaborn

Related posts:

Scatterplot with marginal densityplot with SeabornHow to Make Scatterplot with Marginal Density Plots with Seaborn Grouped Boxplot in Python with SeabornGrouped Boxplots in Python with Seaborn Sort bars in barplot descending order with Seaborn PythonHow To Order Bars in Barplot using Seaborn in Python? Bubble plot Seaborn color by variableHow To Make Bubble Plot with Seaborn Scatterplot in Python?

Filed Under: Python, Scatterplot with Marginal Boxplot, Seaborn JointGrid Tagged With: Python, Seaborn

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

Copyright © 2026 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version