shivansh_exp4
shivansh_exp4
Experiment No: 4
Create a bar plot and scatter plot to visualize relationships in a dataset using Matplotlib.
Aim:
To create a bar plot and scatter plot using Matplotlib to visualize relationships in a dataset.
Objective:
Learn how to use Matplotlib to create bar plots and scatter plots.
Understand how visualization helps in analyzing relationships and distributions in data.
Gain hands-on experience in working with Python data visualization libraries.
Theory:
What is Matplotlib?
Matplotlib is a popular Python library used for data visualization. It provides various plotting
functions to represent data trends, distributions, and relationships.
Bar Plot:
A bar plot is used to compare categorical data. It displays data using rectangular bars, where the
height represents the magnitude of each category.
Scatter Plot:
A scatter plot is used to visualize relationships between two numerical variables. It helps in
identifying correlations and patterns.
Python Program:
import matplotlib.pyplot as plt
students = ['ABC', 'DEF', 'IJK']
marks = [85, 90, 78]
study_hours = [5, 6, 4]
plt.figure(figsize=(10, 5))
plt.bar(students, marks, color='skyblue')
plt.title('Student Marks Comparison')
plt.xlabel('Students')
plt.ylabel('Marks')
plt.show()
plt.figure(figsize=(10, 5))
plt.scatter(study_hours, marks, color='green')
plt.title('Study Hours vs Marks')
plt.xlabel('Study Hours')
plt.ylabel('Marks')
plt.show()
Conclusion:
Output (Screenshots):