Data Visualisation with Matplotlib
— Detailed Demo Guide
(Chapter 4: Plotting Data using Matplotlib — Class
XII Informatics Practices)
1. Why This Chapter Matters (30-second
opening for students)
Raw numbers are hard to read at a glance. A table of 40 students’
marks tells you very little in one look — but a bar chart of the same
data instantly shows who scored highest, who is struggling, and how
the class is doing overall.
Say this to open the demo: > “Numbers tell you the facts. A chart
tells you the story behind the facts.”
Real-life visualisations students already know: a speedometer, a fever
chart on a medical report, a cricket score run-rate graph, Google
Maps traffic colours.
2. Setup (do this before class)
pip install matplotlib pandas
import [Link] as plt
import pandas as pd
One dataset to use for the ENTIRE demo
Using a single small, relatable dataset throughout makes the demo
feel like one continuous story instead of five random charts.
data = {
'Name': ['Aman', 'Riya', 'Zoya', 'Kabir', 'Meera', 'Ishaan'],
'Marks': [78, 92, 85, 65, 88, 73],
'StudyHours': [3, 6, 5, 2, 5.5, 3.5],
'Subject_Time': [2, 3, 4, 1, 3, 2] # hours spent on IP per
week
}
df = [Link](data)
print(df)
Keep this DataFrame open in the notebook/IDE — every chart below
reuses df.
3. Core Concepts to Explain First (2
minutes)
Term Meaning Analogy
The entire
Figure The whole page
window/canvas
The actual chart The drawing on the
Axes/Plot
inside the figure page
[Link]() Draws a line chart —
[Link]() Displays the chart “Print” button
The Matplotlib
pyplot module used for The toolbox
plotting
import [Link] as plt
plt is just an alias — like calling a friend by nickname instead of full
name.
4. LIVE DEMO — Build-Up in 5 Stages
Stage 1: The Bare Minimum Line Chart
Goal: Show that 3 lines of code = a chart.
[Link](df['Name'], df['Marks'])
[Link]()
Talking point: “This already visualises marks trend across students
— but it’s plain. Let’s make it useful.”
Stage 2: Add Customisation (Chapter 4.3)
Introduce one customisation at a time — this mirrors how the
textbook builds it up.
a) Marker — highlights each data point
[Link](df['Name'], df['Marks'], marker='o')
[Link]()
b) Colour
[Link](df['Name'], df['Marks'], marker='o', color='green')
[Link]()
c) Linewidth & Linestyle
[Link](df['Name'], df['Marks'], marker='o', color='green',
linewidth=2, linestyle='--')
[Link]()
d) Labels, Title, Legend (always add — real charts must be labelled)
[Link](df['Name'], df['Marks'], marker='o', color='green',
linewidth=2, linestyle='--', label='Marks')
[Link]('Student Marks Overview')
[Link]('Student Name')
[Link]('Marks Obtained')
[Link]()
[Link]()
Talking point: “Notice — same data, same chart type, but now
anyone can understand it without you explaining it verbally. That’s the
whole point of visualisation.”
Stage 3: The Pandas Shortcut (Chapter 4.4)
Show that Pandas can plot directly from a DataFrame — less code,
same Matplotlib engine underneath.
[Link](x='Name', y='Marks', kind='line', marker='o', title='Marks
Trend')
[Link]()
Talking point: “Matplotlib is the engine. Pandas .plot() is the
shortcut steering wheel built on top of it — same destination, fewer
turns.”
Stage 4: One Dataset, Five Different Chart Types
This is the heart of the demo — show how the same data tells five
different stories depending on chart type chosen.
4.1 Line Chart — for TREND / change over a sequence
[Link](x='Name', y='StudyHours', kind='line', marker='o',
title='Study Hours per Student')
[Link]('Student'); [Link]('Hours'); [Link]()
Use when: Data has an order/sequence — days, months, roll
numbers, test attempts.
4.2 Bar Chart — for COMPARISON across categories
[Link](x='Name', y='Marks', kind='bar', color='skyblue',
title='Marks Comparison')
[Link]('Student'); [Link]('Marks'); [Link]()
Use when: Comparing separate, unrelated categories side by side
(students, subjects, sections). Ask the class: “Why does a bar chart
feel more natural here than a line chart?” → because students aren’t a
continuous sequence, they’re separate individuals.
4.3 Histogram — for DISTRIBUTION of one numeric column
df['Marks'].plot(kind='hist', bins=4, color='orange',
edgecolor='black',
title='Distribution of Marks')
[Link]('Marks Range'); [Link]()
Use when: You want to know how values are spread — e.g., how
many students fall in 60-70, 70-80, 80-90, 90-100. Key teaching
point (common confusion): A bar chart compares different
categories; a histogram groups one continuous variable into ranges
(bins). This is the #1 thing students mix up — spend extra time here.
4.4 Scatter Chart — for RELATIONSHIP between two numeric
variables
[Link](x='StudyHours', y='Marks', kind='scatter', color='red',
title='Study Hours vs Marks')
[Link]('Study Hours'); [Link]('Marks'); [Link]()
Use when: Checking if two variables move together — does more
study time relate to more marks? Talking point: “Look — the dots
roughly rise together. That’s a positive relationship, and a scatter
chart is the only chart type that shows this clearly.”
4.5 Pie Chart — for SHARE / proportion of a whole
df.set_index('Name')['Subject_Time'].plot(kind='pie',
autopct='%1.1f%%',
title='Weekly IP Study
Time Share')
[Link]('')
[Link]()
Use when: Showing parts of a total that add up to 100% — e.g., how
a week’s study time is split, or subject-wise weightage in a paper.
Stage 5: Chart Selection Cheat-Sheet (put this on the
board/slide)
Question you’re
Best chart Example
answering
How did it change
Line Marks across 5 tests
over time/sequence?
How do categories Marks of different
Bar
compare? students
How is one variable Distribution of class
Histogram
spread out? marks
Is there a
relationship between Scatter Study hours vs marks
two variables?
What’s each part’s Time spent per
Pie
share of the whole? subject
5. Suggested 10-Minute Demo Script
(minute-by-minute)
Time What to do
Show the raw DataFrame df —
0:00–1:00 “this is just numbers, hard to
interpret”
Stage 1 & 2 — build up one bare
1:00–2:30 line chart into a labelled, styled
chart
Stage 3 — show the Pandas
2:30–3:30
.plot() shortcut
Line chart — Study Hours per
3:30–4:30
student
4:30–5:30 Bar chart — Marks comparison
Histogram — Marks distribution
5:30–6:30
(clarify vs bar chart)
Scatter chart — Study Hours vs
6:30–7:30
Marks
7:30–8:30 Pie chart — Subject time share
Recap with the cheat-sheet table
8:30–10:00
+ Q&A
6. Common Student Questions (be ready
for these)
“What’s the difference between bar chart and histogram?” →
Bar = separate categories; Histogram = one variable split into
ranges.
“Why did my chart not show?” → Missing [Link](), especially
outside Jupyter.
“Can I use Matplotlib directly instead of Pandas .plot()?” →
Yes, .plot() is just a convenience wrapper; both use Matplotlib
underneath.
“How do I change chart size?” → [Link](figsize=(8,5))
before plotting.
“How do I save the chart as an image?” →
[Link]('[Link]') before [Link]().
7. Quick Reference — All Customisation
Options Used Today
[Link](x, y,
color='green', # line/point colour
marker='o', # point marker style
('o','*','x','s')
linewidth=2, # thickness of line
linestyle='--', # '-' solid, '--' dashed, ':' dotted
label='Marks') # name shown in legend
[Link]('Chart Title')
[Link]('X-axis label')
[Link]('Y-axis label')
[Link]()
[Link](figsize=(8,5)) # chart size
[Link]('[Link]') # save as image
[Link]() # display chart
8. Optional Practice Task to Assign After
the Demo
Give students a small CSV (5–10 rows, columns: Name, Marks,
Attendance%) and ask them to: 1. Load it with pd.read_csv() 2. Plot a
bar chart of Marks 3. Plot a scatter chart of Attendance% vs Marks 4.
Answer in one line: “What does the scatter chart tell you about
attendance and performance?”
This reinforces both Chapter 2/3 (Pandas) and Chapter 4
(visualisation) together.