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.



Follow us on Facebook and Twitter for latest update.