Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Joint Plot | Plotting with Seaborn
Ultimate Visualization with Python

bookJoint Plot

Note
Definition

Joint plot is a rather unique plot, since it combines multiple plots. It is a chart that shows the relationship between two variables along with their individual distributions.

A joint plot combines three elements:

  • a histogram on top (distribution of the x-variable);
  • a histogram on the right (distribution of the y-variable);
  • a scatter plot in the center (relationship between the two variables).

Here is an example:

Joint plot example

Data for the Joint Plot

seaborn.jointplot() uses three key parameters:

  • data β€” the DataFrame,
  • x β€” variable for the top histogram,
  • y β€” variable for the right histogram.

x and y may be column names or array-like objects.

12345678
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris flowers species iris_df = sns.load_dataset("iris") sns.jointplot(data=iris_df, x="sepal_length", y="sepal_width") plt.show()
copy

The example is recreated by passing a DataFrame to data and specifying column names for x and y.

Plot in the Middle

The kind parameter controls the central plot type. Default: 'scatter'. Other options include: 'kde', 'hist', 'hex', 'reg', 'resid'.

12345678
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris flowers species iris_df = sns.load_dataset("iris") sns.jointplot(data=iris_df, x="sepal_length", y="sepal_width", kind='reg') plt.show()
copy

Plot Kinds

Besides scatter, you can choose:

  • reg β€” adds a linear regression fit;
  • resid β€” plots regression residuals;
  • hist β€” bivariate histogram;
  • kde β€” two-variable KDE;
  • hex β€” hexbin plot showing density using colored hexagonal bins.
Note
Study More

As usual, you can explore more options and parameters in jointplot() documentation.

Also, it is worth exploring the mentioned topics:
residplot() documentation;
Bivariate histogram example;
Hexbin plot example.

Task

Swipe to start coding

  1. Use the correct function to create a joint plot.
  2. Use weather_df as the data for the plot (the first argument).
  3. Set the 'Boston' column for the x-axis variable (the second argument).
  4. Set the 'Seattle' column for the y-axis variable (the third argument).
  5. Set the plot in the middle to have a regression line (the rightmost argument).

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 5. ChapterΒ 5
single

single

Ask AI

expand

Ask AI

ChatGPT

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

Suggested prompts:

What does the 'kind' parameter do in jointplot?

Can you explain the difference between the available plot kinds?

How can I customize the appearance of the jointplot?

close

Awesome!

Completion rate improved to 3.85

bookJoint Plot

Swipe to show menu

Note
Definition

Joint plot is a rather unique plot, since it combines multiple plots. It is a chart that shows the relationship between two variables along with their individual distributions.

A joint plot combines three elements:

  • a histogram on top (distribution of the x-variable);
  • a histogram on the right (distribution of the y-variable);
  • a scatter plot in the center (relationship between the two variables).

Here is an example:

Joint plot example

Data for the Joint Plot

seaborn.jointplot() uses three key parameters:

  • data β€” the DataFrame,
  • x β€” variable for the top histogram,
  • y β€” variable for the right histogram.

x and y may be column names or array-like objects.

12345678
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris flowers species iris_df = sns.load_dataset("iris") sns.jointplot(data=iris_df, x="sepal_length", y="sepal_width") plt.show()
copy

The example is recreated by passing a DataFrame to data and specifying column names for x and y.

Plot in the Middle

The kind parameter controls the central plot type. Default: 'scatter'. Other options include: 'kde', 'hist', 'hex', 'reg', 'resid'.

12345678
import seaborn as sns import matplotlib.pyplot as plt # Loading the dataset with data about three different iris flowers species iris_df = sns.load_dataset("iris") sns.jointplot(data=iris_df, x="sepal_length", y="sepal_width", kind='reg') plt.show()
copy

Plot Kinds

Besides scatter, you can choose:

  • reg β€” adds a linear regression fit;
  • resid β€” plots regression residuals;
  • hist β€” bivariate histogram;
  • kde β€” two-variable KDE;
  • hex β€” hexbin plot showing density using colored hexagonal bins.
Note
Study More

As usual, you can explore more options and parameters in jointplot() documentation.

Also, it is worth exploring the mentioned topics:
residplot() documentation;
Bivariate histogram example;
Hexbin plot example.

Task

Swipe to start coding

  1. Use the correct function to create a joint plot.
  2. Use weather_df as the data for the plot (the first argument).
  3. Set the 'Boston' column for the x-axis variable (the second argument).
  4. Set the 'Seattle' column for the y-axis variable (the third argument).
  5. Set the plot in the middle to have a regression line (the rightmost argument).

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Β 5. ChapterΒ 5
single

single

some-alt