w3resource

Creating a Bar Plot with Pandas and Matplotlib

Pandas: Visualization Integration Exercise-3 with Solution

Write a Pandas program that scatters Plot with Seaborn and Pandas.

This exercise shows how to create a scatter plot using Pandas and Seaborn to visualize relationships between two variables.

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]
})

# Create a scatter plot of 'Height' vs 'Weight'
sns.scatterplot(x='Height', y='Weight', data=df)

# Add a title
plt.title('Height vs Weight')

# Display the plot
plt.show()

Output:

Pandas - Creating Scatter Plot with Seaborn andPandas

Explanation:

  • Created a DataFrame with 'Height' and 'Weight' columns.
  • Used sns.scatterplot() to plot 'Height' vs 'Weight' as a scatter plot.
  • Added a title and displayed the plot using plt.show().

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/create-scatter-plot-using-seaborn-and-pandas.php