w3resource

Pandas - Creating a Pair Plot using Seaborn for Multiple variable analysis

Pandas: Visualization Integration Exercise-6 with Solution

Write a Pandas program to create a Pair Plot with Seaborn.

This exercise demonstrates how to create a pair plot using Seaborn to visualize relationships between all numerical columns in a DataFrame.

Sample Solution :

Code :

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Create a sample DataFrame
df = pd.DataFrame({
    'Height': [150, 160, 170, 180, 190],
    'Weight': [50, 60, 70, 80, 90],
    'Age': [22, 25, 30, 35, 40]
})

# Create a pair plot to visualize relationships between columns
sns.pairplot(df)

# Display the plot
plt.show()

Output:

Pandas - Pair Plot with Seaborn

Explanation:

  • Created a DataFrame with numerical columns.
  • Used sns.pairplot() to generate scatter plots for every pair of numerical columns, visualizing the relationships.
  • Displayed the resulting pair plot.

Python-Pandas Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/python-exercises/pandas/pandas-create-a-pair-plot-using-seaborn-for-multiple-variable-analysis.php