Introduction

In this tutorial, we want to create a Jointplot. In order to do this, we use the jointplot() function of Seaborn.

Import Libraries

First, we import the following python modules:

import seaborn as sns
import matplotlib.pyplot as plt

Load Data

We would like to use a seaborn sample dataset. Let's load the "penguins" dataset into python.

penguins_df = sns.load_dataset("penguins")

penguins_df.head()

Jointplot

A Jointplot is very helpful to plot two variables. On the one hand, the individual distribution of each variable is visualized. On the other hand, the relationship between the two variables is visualized.

In the following, we want to use a jointplot to analyze the relationship between the flipper length and the bill length of penguins.

In order to do this, we use the jointplot() function. We consider various visualization options and try different parameters. First, we analyize all penguins in general and then we distinguish between different penguin species.

Example 1

Let's set the value "scatter" for the kind parameter.

sns.jointplot(data=penguins_df, x='flipper_length_mm', y='bill_length_mm',
              color = 'darkcyan',
              kind = 'scatter')

plt.show()

Example 2

Let's set the value "hex" for the kind parameter.

sns.jointplot(data=penguins_df, x='flipper_length_mm', y='bill_length_mm',
              color = 'darkcyan',
              kind = 'hex')

plt.show()

Example 3

Let's set the value "kde" for the kind parameter.

sns.jointplot(data=penguins_df, x='flipper_length_mm', y='bill_length_mm',
              color = 'darkcyan',
              kind = 'kde')

plt.show()

Example 4

Let's set the value "scatter" for the kind parameter and "species" for the hue parameter.

sns.jointplot(data=penguins_df, x='flipper_length_mm', y='bill_length_mm', 
              palette = 'dark:cyan',
              hue = 'species',
              kind = 'scatter')

plt.show()

Example 5

Let's set the value "kde" for the kind parameter and "species" for the hue parameter.

sns.jointplot(data=penguins_df, x='flipper_length_mm', y='bill_length_mm',
              palette = 'dark:cyan',
              hue = 'species', 
              kind = 'kde')

plt.show()

Conclusion

Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to create a Jointplot. We can simply use the jointplot() function of Seaborn. Try it yourself!

Instagram

Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.