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

Swipe to show menu

book
Joint 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.

Basically, it has three elements by default:

  • Histogram on the top which represents the distribution of a certain variable;

  • Histogram on the right which represents the distribution of another variable;

  • Scatter plot in the middle which shows the relationship between these two variables.

Here is an example of a joint plot:

Data for the Joint Plot

seaborn has a jointplot() function which, similarly to countplot() and kdeplot(), has three most important parameters:

  • data;

  • x;

  • y.

The x and y parameters specify the variables to plot, which correspond to the histograms on the right and top. These parameters can be array-like objects or column names when the data parameter is a DataFrame.

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 initial example has been recreated by assigning a DataFrame to the data parameter and specifying column names for x and y.

Plot in the Middle

Another quite useful parameter is kind which specifies the plot you have in the middle. 'scatter' is its default value. Here are other possible plots: 'kde', 'hist', 'hex', 'reg', 'resid'. Feel free to experiment with different plots:

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

Although the scatter plot is the most common choice for the central plot, there are several other options available:

  • reg: Adds a linear regression fit to the scatter plot, useful for checking correlation between variables;

  • resid: Displays the residuals from a linear regression;

  • hist: Shows a bivariate histogram for two variables;

  • kde: Creates a KDE plot;

  • hex: Produces a hexbin plot, where hexagonal bins replace individual points, and bin color indicates data density.

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

Ask AI

expand
ChatGPT

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

book
Joint 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.

Basically, it has three elements by default:

  • Histogram on the top which represents the distribution of a certain variable;

  • Histogram on the right which represents the distribution of another variable;

  • Scatter plot in the middle which shows the relationship between these two variables.

Here is an example of a joint plot:

Data for the Joint Plot

seaborn has a jointplot() function which, similarly to countplot() and kdeplot(), has three most important parameters:

  • data;

  • x;

  • y.

The x and y parameters specify the variables to plot, which correspond to the histograms on the right and top. These parameters can be array-like objects or column names when the data parameter is a DataFrame.

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 initial example has been recreated by assigning a DataFrame to the data parameter and specifying column names for x and y.

Plot in the Middle

Another quite useful parameter is kind which specifies the plot you have in the middle. 'scatter' is its default value. Here are other possible plots: 'kde', 'hist', 'hex', 'reg', 'resid'. Feel free to experiment with different plots:

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

Although the scatter plot is the most common choice for the central plot, there are several other options available:

  • reg: Adds a linear regression fit to the scatter plot, useful for checking correlation between variables;

  • resid: Displays the residuals from a linear regression;

  • hist: Shows a bivariate histogram for two variables;

  • kde: Creates a KDE plot;

  • hex: Produces a hexbin plot, where hexagonal bins replace individual points, and bin color indicates data density.

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
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt