AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Informatics Practices

Plotting Data using Matplotlib

Standard difficulty · 20 questions · 40 marks · Time: 38 minutes

Name: Date: Score: ____ / 40

Show your working for Sections B and C. Answers are on the last page — try every question first!

Section A — Choose the correct answer8 × 1 = 8 marks
1.
The usual way to import the plotting module of Matplotlib is:
  1. import pyplot.matplotlib
  2. include matplotlib
  3. import matplotlib as pd
  4. import matplotlib.pyplot as plt
2.
Which function would you use to draw a chart of the number of students in each house of a school?
  1. plt.bar()
  2. plt.scatter()
  3. plt.pie()
  4. plt.barh()
3.
Which statement shows a box naming each line by its label?
  1. plt.show()
  2. plt.xticks()
  3. plt.xlabel()
  4. plt.legend()
4.
How many values fall in the bar for the bin 35–40 in this histogram?
import matplotlib.pyplot as plt
data = [32, 31, 32, 30, 40, 29, 24, 20, 31, 33, 35]
plt.hist(data, bins=[20, 25, 30, 35, 40])
plt.show()
  1. 3
  2. 6
  3. 1
  4. 2
5.
At which point is the line highest?
import matplotlib.pyplot as plt
x = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
y = [63, 71, 75, 76, 13, 38]
plt.plot(x, y, marker='o')
plt.show()
  1. Mar
  2. Feb
  3. Jan
  4. Apr
6.
A DataFrame df has 7 rows and the columns Name, Q1, Q2, Q3 and Q4. How many bars does this statement draw?
df.plot(kind='bar', x='Name', y='Q4')
  1. 8
  2. 28
  3. 7
  4. 1
7.
In a plotting statement, what does the argument edgecolor='black' do?
  1. draws a black border around each bar
  2. makes the pandas plot() function draw a histogram
  3. makes the point markers bigger
  4. makes the pandas plot() function draw a bar chart
8.
Which bar is the tallest?
import matplotlib.pyplot as plt
x = ['Red', 'Blue', 'Green', 'Yellow', 'Orange', 'Purple']
h = [56, 30, 32, 17, 23, 22]
plt.bar(x, h)
plt.show()
  1. Red
  2. Blue
  3. Purple
  4. Orange
Section B — Short answer8 × 2 = 16 marks
9.
What is the purpose of plotting data?
10.
How many bars in this chart are taller than 37?
import matplotlib.pyplot as plt
x = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
h = [21, 49, 36, 34, 37]
plt.bar(x, h)
plt.show()
11.
Write the height of the bar for the bin 10–20.
import matplotlib.pyplot as plt
data = [24, 40, 24, 40, 36, 40, 30, 21, 20, 14, 39]
plt.hist(data, bins=[10, 20, 30, 40])
plt.show()
12.
Fill in the blank so that the statement names the y-axis “Sales”.
plt.______('Sales')
13.
What is the y value of the point plotted at May?
import matplotlib.pyplot as plt
x = ['Jan', 'Feb', 'Mar', 'Apr', 'May']
y = [79, 20, 35, 41, 25]
plt.plot(x, y, marker='o')
plt.show()
14.
Which bar is the shortest?
import matplotlib.pyplot as plt
x = ['Pens', 'Books', 'Bags', 'Bottles']
h = [47, 53, 45, 27]
plt.bar(x, h)
plt.show()
15.
What is the total height of all the bars in this histogram (the number of values counted)?
import matplotlib.pyplot as plt
data = [19, 30, 24, 30, 19, 28, 19, 27, 15, 17, 25, 15, 30]
plt.hist(data, bins=[15, 20, 25, 30])
plt.show()
16.
In how many places does this line go down from one point to the next?
import matplotlib.pyplot as plt
x = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul']
y = [48, 67, 51, 25, 73, 69, 31]
plt.plot(x, y, marker='o')
plt.show()
Section C — Word problems4 × 4 = 16 marks
17.
Write a program to plot the marks of a student in five subjects as a bar chart with a title, axis labels and red bars.
18.
Write a program to draw a bar chart of these values with the title “Students in each club”, the x-axis named “Category”, the y-axis named “Value”, blue bars, and save it as chart.png.
Mon: 32, Tue: 44, Wed: 26, Thu: 34
19.
Write the height of each bar of this histogram.
import matplotlib.pyplot as plt
data = [22, 61, 22, 80, 50, 40, 70, 30, 44, 47, 75, 80, 31]
plt.hist(data, bins=[20, 40, 60, 80])
plt.show()
(a) 20–40 (b) 40–60 (c) 60–80
20.
import matplotlib.pyplot as plt
m = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
a = [42, 53, 79, 83, 73, 56]
b = [79, 42, 61, 86, 81, 76]
plt.plot(m, a, label='Shop A')
plt.plot(m, b, label='Canteen', linestyle='dashed')
plt.legend()
plt.show()
(a) In which month is the Shop A line highest?
(b) In how many months is the dashed line above the solid one?
(c) What is the total of the Shop A values?
AmbifulWorksheets
Practice that never repeats
CBSE · Class 12 · Informatics Practices

Answer key

Plotting Data using Matplotlib · AW-12IP-PLT-2026-V1 · For parents — fold back or tear off before handing the sheet to your child.

QAnswerWorking
1(d) import matplotlib.pyplot as plt—
2(a) plt.bar()—
3(d) plt.legend()—
4(d) 2the last bin includes both 35 and 40
5(d) Aprthe largest y value is 76
6(c) 77 rows × 1 column of values
7(a) draws a black border around each bar—
8(a) RedRed has the largest height, 56
9To show data as a picture so that trends, comparisons, patterns and unusual values can be seen and understood quickly.—
101heights above 37: 49
111values from 10 up to but not including 20
12ylabelplt.ylabel()
1325the 5th pair of the lists
14BottlesBottles has the smallest height, 27
1513every value lies between 15 and 30, so all 13 are counted
164compare each y value with the one before it: 48, 67, 51, 25, 73, 69, 31
17import matplotlib.pyplot as plt
sub = ['Maths', 'Science', 'English', 'Hindi', 'IP']
marks = [78, 85, 69, 74, 90]
plt.bar(sub, marks, color='red')
plt.title('Marks in Term 1')
plt.xlabel('Subject')
plt.ylabel('Marks')
plt.show()
lists (1); bar with colour (1); title and labels (1); show (1)
18import matplotlib.pyplot as plt
x = ['Mon', 'Tue', 'Wed', 'Thu']
h = [32, 44, 26, 34]
plt.bar(x, h, color='blue')
plt.title('Students in each club')
plt.xlabel('Category')
plt.ylabel('Value')
plt.savefig('chart.png')
plt.show()
one mark each for the lists, plt.bar, the title and labels, and savefig before show
19(a) 4; (b) 4; (c) 5each bin includes its left edge; the last bin includes 80 too
20(a) Apr; (b) 4; (c) 386(b) the dashed line is Canteen: compare b with a month by month