Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Creating Joint Distribution Plots | Section
Statistical Visualization with Seaborn

bookCreating Joint Distribution Plots

JointGrid is the underlying figure-level object used to create bivariate plots with marginal univariate plots.

When you use sns.jointplot(), it creates a JointGrid for you automatically. However, using JointGrid directly gives you a blank canvas. You can explicitly decide what to draw in the center and what to draw on the sides.

The Workflow

  1. Initialize: create the grid with your data and variables. At this point, it is empty;
  2. g.plot_joint(): draws the bivariate plot in the center (e.g., scatter plot);
  3. g.plot_marginals(): draws the univariate plots on the top and right axes (e.g., histogram or KDE).

Example

Here we create a custom grid with a regression plot in the center and KDE curves on the sides.

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('penguins') # 1. Initialize the grid g = sns.JointGrid(data=df, x='bill_length_mm', y='bill_depth_mm') # 2. Draw the plots g.plot_joint(sns.regplot, scatter_kws={'alpha': 0.5}) # Center: Regression g.plot_marginals(sns.kdeplot, fill=True) # Sides: KDE plt.show()
copy
Task

Swipe to start coding

Analyze the relationship between bill length and depth, distinguishing by species.

  1. Set the style to 'ticks'. Change the figure background color to 'lightcyan' ('figure.facecolor').
  2. Initialize the JointGrid (g):
    • Map 'bill_length_mm' to x and 'bill_depth_mm' to y.
    • Color points by 'species' (hue).
    • Use the 'viridis' palette.
  3. Center plot (plot_joint):
    • Draw a scatterplot.
    • Make points semi-transparent (alpha=0.5).
    • Set point border color (edgecolor) to 'pink'.
    • Set border thickness (linewidth) to 1.
  4. Side plots (plot_marginals):
    • Draw a histplot.
    • Add a KDE curve (kde=True).
  5. Display the plot.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 20
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookCreating Joint Distribution Plots

Swipe to show menu

JointGrid is the underlying figure-level object used to create bivariate plots with marginal univariate plots.

When you use sns.jointplot(), it creates a JointGrid for you automatically. However, using JointGrid directly gives you a blank canvas. You can explicitly decide what to draw in the center and what to draw on the sides.

The Workflow

  1. Initialize: create the grid with your data and variables. At this point, it is empty;
  2. g.plot_joint(): draws the bivariate plot in the center (e.g., scatter plot);
  3. g.plot_marginals(): draws the univariate plots on the top and right axes (e.g., histogram or KDE).

Example

Here we create a custom grid with a regression plot in the center and KDE curves on the sides.

1234567891011121314
import seaborn as sns import matplotlib.pyplot as plt # Load dataset df = sns.load_dataset('penguins') # 1. Initialize the grid g = sns.JointGrid(data=df, x='bill_length_mm', y='bill_depth_mm') # 2. Draw the plots g.plot_joint(sns.regplot, scatter_kws={'alpha': 0.5}) # Center: Regression g.plot_marginals(sns.kdeplot, fill=True) # Sides: KDE plt.show()
copy
Task

Swipe to start coding

Analyze the relationship between bill length and depth, distinguishing by species.

  1. Set the style to 'ticks'. Change the figure background color to 'lightcyan' ('figure.facecolor').
  2. Initialize the JointGrid (g):
    • Map 'bill_length_mm' to x and 'bill_depth_mm' to y.
    • Color points by 'species' (hue).
    • Use the 'viridis' palette.
  3. Center plot (plot_joint):
    • Draw a scatterplot.
    • Make points semi-transparent (alpha=0.5).
    • Set point border color (edgecolor) to 'pink'.
    • Set border thickness (linewidth) to 1.
  4. Side plots (plot_marginals):
    • Draw a histplot.
    • Add a KDE curve (kde=True).
  5. Display the plot.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 20
single

single

some-alt