Matplotlib - Practice Questions
Q1. Write a Python program to create a line plot for the following two lists:
import [Link] as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 5, 7]
[Link](x, y, label='Sample Line', color='red', linestyle='--', marker='o',
linewidth=2)
[Link]('X Axis')
[Link]('Y Axis')
[Link]('Line Plot Example')
[Link]()
[Link]()
[Link]()
Q2. Write a Python program to create a bar chart for the following data:
import [Link] as plt
categories = ['Math', 'Science', 'English', 'History']
scores = [88, 92, 81, 76]
[Link](categories, scores, label='Scores')
[Link]('Subjects')
[Link]('Scores')
[Link]('Student Score')
[Link]()
[Link]()
Q3. Write a Python program to create a histogram to show the distribution of scores using 5
bins:
import [Link] as plt
scores = [70, 72, 74, 76, 76, 78, 80, 82, 84, 84, 85, 88, 90, 92, 95]
[Link](scores, bins=5, edgecolor='black')
[Link]('Score Ranges')
[Link]('Number of Students')
[Link]('Score Distribution')
[Link]()
Q4. Write a Python program to create a pie chart showing percentage of time spent on
activities:
import [Link] as plt
activities = ['Sleep', 'Study', 'Exercise', 'Leisure']
hours = [8, 6, 2, 8]
[Link](hours, labels=activities, autopct='%1.1f%%')
[Link]('Daily Time Spent on Activities')
[Link]()
Q5. Write a Python program to create a box plot for the following data:
import [Link] as plt
data = [75, 80, 85, 90, 90, 92, 95, 100, 100, 105, 110]
[Link](data)
[Link]('Box Plot of Scores')
[Link]('Data Set')
[Link]('Score')
[Link]()