Class XI – Computer Science / Artificial Intelligence
Worksheet: Data Visualization using Matplotlib
(Programming Based)
Topics: Line Chart, Bar Chart, Column Chart, Pie Chart, Box Plot, Scatter
Plot
Total Marks: 40
Instructions:
Write Python programs using the Matplotlib library.
Add appropriate title, axis labels, and legends wherever required
Section A – Programming Questions (2 Marks Each)
Q1. Write a Python program to plot a line chart showing the monthly sales
(in thousands) of a bookstore.
Month Jan Feb Mar Apr May Jun
Sales 35 42 40 50 55 60
Include:
Blue line
Circle markers
Grid
Proper title and axis labels
Q2. Write a Python program to create a vertical bar (column) chart
representing the marks scored by five students.
Student A B C D E
Marks 82 91 76 88 95
Display the marks above each bar.
Q3. A company wants to compare the sales of four products.
Product Laptop Tablet Mobile Smart Watch
Units Sold 150 95 210 120
Write a Python program to create a bar chart using different colors for
each bar.
Q4. Write a Python program to draw a pie chart showing the percentage
distribution of household expenses.
Category Food Rent Education Transport Savings
Percentage 30 35 15 10 10
Highlight the "Education" slice.
Q5. Write a Python program to create a scatter plot showing the
relationship between study hours and marks.
Study Hours 2 3 4 5 6 7 8
Marks 45 50 58 65 72 80 92
Section B – Programming & Analysis (4 Marks Each)
Q6. A school collected the heights (in cm) of 15 students.
145, 148, 150, 151, 152, 153, 154,155, 156, 157, 158, 160, 162, 164, 170
Write a Python program to draw a Box Plot. Also identify:
Median
Maximum value
Minimum value
Q7. Write a Python program to plot two line charts on the same graph
comparing the annual sales of Company A and Company B.
Year 2020 2021 2022 2023 2024
Company A 50 60 70 80 90
Year 2020 2021 2022 2023 2024
Company B 45 55 68 76 88
Include:
Legend
Grid
Different colors and markers
Q8. Write a Python program to create a scatter plot for the following data.
Temperature (°C) 18 20 22 24 26 28 30
Ice Cream Sales 30 35 42 50 58 70 82
Based on the graph, comment on the relationship between
temperature and sales.
Q9. Write a Python program to create a pie chart showing the percentage
of students choosing different career options.
Career Engineering Medical Commerce Arts Other
Students 40 25 20 10 5
Display percentage values on each slice.
Section C – Higher Order Programming Questions (6 Marks Each)
Q10. Data Visualization Dashboard
A school's examination cell wants a graphical report for Class XI
performance.
Given:
subjects=["English","Math","Physics","Chemistry","CS"]
marks=[82,95,78,74,91]
Write a Python program that displays:
1. A Bar Chart of marks.
2. A Line Chart of marks.
3. A Pie Chart showing the contribution of each subject's marks to the
total.
Each graph should have:
Appropriate title
Axis labels (where applicable)
Different colors
Grid (except Pie Chart)
Q11. Real-Life Data Analysis Challenge
A fitness coach recorded the daily walking steps of a student for one week.
Day Mon Tue Wed Thu Fri Sat Sun
Steps 6500 7200 8000 7600 9000 10500 9800
Write a Python program to:
1. Draw a Line Chart.
2. Draw a Bar Chart.
3. Identify the day with the highest number of steps.
4. Calculate the average number of steps using Python.
Q12. Integrated Visualization Challenge
A retail store has recorded monthly profit (₹ in thousands).
Month Jan Feb Mar Apr May Jun
Profit 15 18 20 16 25 28
Write a Python program to:
1. Plot a Line Chart with markers.
2. Plot a Scatter Plot using the same data.
3. Compare both charts and write two advantages of using a Scatter
Plot over a Line Chart for data analysis.
Class XI – Computer Science / Artificial Intelligence
Worksheet: Data Visualization using Matplotlib
(Programming Based)
Solution 1 – Line Chart
import [Link] as plt
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sales = [35, 42, 40, 50, 55, 60]
[Link](months, sales, color='blue', marker='o', linewidth=2)
[Link]("Monthly Bookstore Sales")
[Link]("Month")
[Link]("Sales (₹ Thousands)")
[Link](True)
for i in range(len(months)):
[Link](months[i], sales[i] + 1.5, str(sales[i]),
ha='center', va='bottom', fontsize=9, fontweight='bold', color='darkblue')
[Link](30, 70)
[Link]()
Solution 2 – Column Chart
import [Link] as plt
students = ["A", "B", "C", "D", "E"]
marks = [82, 91, 76, 88, 95]
bars = [Link](students, marks, color='skyblue')
[Link]("Student Marks")
[Link]("Students")
[Link]("Marks")
for bar in bars:
[Link](bar.get_x()+bar.get_width()/2,
bar.get_height()+1,
str(int(bar.get_height())),
ha='center')
[Link]()
Solution 3 – Bar Chart
import [Link] as plt
products = ["Laptop", "Tablet", "Mobile", "Smart Watch"]
sales = [150, 95, 210, 120]
colors = ["red", "green", "blue", "orange"]
[Link](products, sales, color=colors)
[Link]("Product Sales")
[Link]("Products")
[Link]("Units Sold")
[Link](True)
[Link]()
Solution 4 – Pie Chart
import [Link] as plt
categories = ["Food", "Rent", "Education", "Transport", "Savings"]
percent = [30, 35, 15, 10, 10]
explode = (0, 0, 0.1, 0, 0)
[Link](percent,
labels=categories,
autopct="%1.1f%%",
explode=explode,
startangle=90)
[Link]("Household Expenses")
[Link]()
Solution 5 – Scatter Plot
import [Link] as plt
hours = [2,3,4,5,6,7,8]
marks = [45,50,58,65,72,80,92]
[Link](hours, marks, color='red')
[Link]("Study Hours vs Marks")
[Link]("Study Hours")
[Link]("Marks")
[Link](True)
[Link]()
Solution 6 – Box Plot
import [Link] as plt
import statistics
heights = [145, 148, 150, 151, 152, 153, 154,
155, 156, 157, 158, 160, 162, 164, 170]
# Box plot with added attributes
[Link](heights,
vert=True,
patch_artist=True,
notch=True,
showmeans=True,
boxprops=dict(facecolor='orange', color='Red'),
capprops=dict(color='black'),
whiskerprops=dict(color='yellow'),
flierprops=dict(marker='o', markerfacecolor='red', markersize=8))
[Link]("Height Distribution")
[Link]("Height (cm)")
[Link](axis='y', linestyle='--', alpha=0.4)
[Link]()
print("Minimum =", min(heights))
print("Maximum =", max(heights))
print("Median =", [Link](heights))
print("Mean =", [Link](heights))
Output
Minimum = 145
Maximum = 170
Median = 154
Solution 7 – Two Line Charts
import [Link] as plt
years = [2020,2021,2022,2023,2024]
companyA = [50,60,70,80,90]
companyB = [45,55,68,76,88]
[Link](years, companyA,
marker='o',
label="Company A")
[Link](years, companyB,
marker='s',
label="Company B")
[Link]("Annual Sales Comparison")
[Link]("Year")
[Link]("Sales")
[Link]()
[Link](True)
[Link]()
Solution 8 – Scatter Plot
import [Link] as plt
temperature = [18,20,22,24,26,28,30]
sales = [30,35,42,50,58,70,82]
[Link](temperature, sales, color="green")
[Link]("Temperature vs Ice Cream Sales")
[Link]("Temperature")
[Link]("Sales")
[Link](True)
[Link]()
print("Observation:")
print("As temperature increases, ice cream sales also increase.")
Solution 9 – Pie Chart
import [Link] as plt
career = ["Engineering","Medical","Commerce","Arts","Other"]
students = [40,25,20,10,5]
[Link](students,
labels=career,
autopct="%1.1f%%",
startangle=90)
[Link]("Career Choice")
[Link]()
Solution 10 – Dashboard
import [Link] as plt
subjects = ["English","Math","Physics","Chemistry","CS"]
marks = [82,95,78,74,91]
# Bar Chart
[Link](figsize=(6,4))
[Link](subjects, marks)
[Link]("Subject Marks")
[Link](True)
[Link]()
# Line Chart
[Link](figsize=(6,4))
[Link](subjects, marks, marker='o')
[Link]("Subject Marks")
[Link](True)
[Link]()
# Pie Chart
[Link](figsize=(6,4))
[Link](marks,
labels=subjects,
autopct="%1.1f%%")
[Link]("Marks Contribution")
[Link]()
Solution 11 – Walking Steps Analysis
import [Link] as plt
days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
steps = [6500,7200,8000,7600,9000,10500,9800]
# Line Chart
[Link](days, steps, marker='o')
[Link]("Daily Walking Steps")
[Link](True)
[Link]()
# Bar Chart
[Link](days, steps)
[Link]("Daily Walking Steps")
[Link]()
highest = max(steps)
day = days[[Link](highest)]
average = sum(steps)/len(steps)
print("Highest Steps:", highest)
print("Day:", day)
print("Average Steps:", average)
Output
Highest Steps = 10500
Day = Sat
Average Steps = 8385.71
Solution 12 – Integrated Visualization
import [Link] as plt
months = ["Jan","Feb","Mar","Apr","May","Jun"]
profit = [15,18,20,16,25,28]
# Line Chart
[Link](figsize=(6,4))
[Link](months,
profit,
marker='o')
[Link]("Monthly Profit")
[Link](True)
[Link]()
# Scatter Plot
[Link](figsize=(6,4))
[Link](months,
profit,
color='red')
[Link]("Monthly Profit Scatter Plot")
[Link](True)
[Link]()
print("Advantages of Scatter Plot")
print("1. Shows correlation between variables.")
print("2. Easily identifies outliers and data clusters.")