Relationship between Horsepower and MPG

Using the mpg dataset available in Seaborn, plot a scatter plot between ‘horsepower’ and ‘mpg’ columns showcasing the relationship between the two.

Example Output:

You can use the sns.scatterplot function, and the mpg dataset can be loaded using sns.load_dataset('mpg').

import seaborn as sns
import matplotlib.pyplot as plt

def plot_mpg_horsepower():
    mpg_data = sns.load_dataset('mpg')
    sns.scatterplot(x='horsepower', y='mpg', data=mpg_data)
    plt.title('Relationship between Horsepower and MPG')



© Let’s Data Science


Unlock AI & Data Science treasures. Log in!