How to Create Seaborn Joint Plot

Ammar Ali Feb 15, 2024
How to Create Seaborn Joint Plot

This tutorial will discuss creating a joint plot of two variables using Seaborn’s jointplot() function.

Seaborn Joint Plot

We can use the jointplot() function to plot two variables in Seaborn. To create the joint plot, we must create a data frame of the given data using the pandas library or numpy and pass it to the jointplot() function using the data argument.

Let’s create a data frame using the DataFrame() function of the pandas library and plot a joint plot using the data frame. See the code below.

import seaborn as snNew
import pandas as pdNew
import matplotlib.pyplot as pltNew

array = [
    [11, 1, 0, 2, 0],
    [3, 8, 0, 1, 0],
    [0, 16, 3, 0, 0],
    [0, 0, 12, 0, 0],
    [0, 0, 0, 13, 0],
    [0, 1, 0, 0, 16],
]

DetaFrame_cm = pdNew.DataFrame(array, range(6), range(5))
snNew.jointplot(data=DetaFrame_cm)
pltNew.show()

Output:

joint plot in seaborn

We can create a numpy array of the given data to plot the five lines using the ndarray() function of the numpy library and use it to plot the five lines. We can change the color palette to give colors to the data points using the palette argument and set its value to a palette name like dark for dark colors.

By default, the legends are set to true, but we can hide the legends by setting the legend argument to false. The graph’s height is six by default, but we can set it to any numeric value using the height argument.

By default, the ratio of marginal axes and joint axes height is set to 5, but we can change it to any numeric value. This ratio sets the size of each plot. By default, the space between the marginal and joint axes is 0.2, but we can change it to any numeric value.

Let’s change the properties mentioned above. See the code below.

import seaborn as snNew
import pandas as pdNew
import matplotlib.pyplot as pltNew

array = [
    [11, 1, 0, 2, 0],
    [3, 8, 0, 1, 0],
    [0, 16, 3, 0, 0],
    [0, 0, 12, 0, 0],
    [0, 0, 0, 13, 0],
    [0, 1, 0, 0, 16],
]

DetaFrame_cm = pdNew.DataFrame(array, range(6), range(5))
snNew.jointplot(
    data=DetaFrame_cm, palette="dark", legend=False, height=5, ratio=3, space=1
)
pltNew.show()

Output:

changing properties of joint plot

Author: Ammar Ali
Ammar Ali avatar Ammar Ali avatar

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.

LinkedIn Facebook

Related Article - Seaborn Plot