Joint Distribution Visualization of MPG and Horsepower

For the mpg dataset, create a joint plot between ‘mpg’ and ‘horsepower’ showcasing both scatter and density plots.

Example Output:

Use the sns.jointplot function with kind="kde", and load the mpg dataset with sns.load_dataset('mpg').

import seaborn as sns
import matplotlib.pyplot as plt

def plot_mpg_jointplot():
    mpg_data = sns.load_dataset('mpg')
    sns.jointplot(x='mpg', y='horsepower', data=mpg_data, kind="kde")
    plt.suptitle('Joint Distribution of MPG and Horsepower', y=1.02)
    plt.show()

plot_mpg_jointplot()

 

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!