Curriculum
Course: Grade XII Informatics Practices
Login
Text lesson

Ch-4 Plotting Data using Matplotlib

School Revise · Class 12 Information Practices · Chapter 4

Plotting Data using Matplotlib

Code 065, Class 12. A chart shows data at a glance. Here we use Matplotlib to draw line, bar and scatter charts, and to label them clearly.

3

chart types

plt

the plotting tool

What this chapter is about

Matplotlib is a Python library for drawing charts. We import it as plt, draw a chart, add a title and labels, and show it.

1. Line, bar and scatter

plt.plot(x, y) draws a line chart, plt.bar(x, y) a bar chart, and plt.scatter(x, y) a scatter chart. plt.show() displays it.

import matplotlib.pyplot as plt plt.plot([1, 2, 3], [2, 4, 6]) plt.show() (a line chart is displayed)

2. Titles and labels

plt.title(“…”) adds a title, plt.xlabel(“…”) and plt.ylabel(“…”) name the axes, and plt.legend() explains multiple lines.

3. Choosing a chart

A line chart shows change over time, a bar chart compares groups, and a scatter chart shows the link between two values.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Draw a line chart.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2, 3], [2, 4, 6]) plt.show()

OUTPUT

a line chart is displayed
Problem 2. Draw a bar chart.

SOLUTION

import matplotlib.pyplot as plt plt.bar([“A”, “B”, “C”], [3, 5, 2]) plt.show()

OUTPUT

a bar chart of A, B, C is displayed
Problem 3. Draw a scatter chart.

SOLUTION

import matplotlib.pyplot as plt plt.scatter([1, 2, 3], [4, 5, 6]) plt.show()

OUTPUT

a scatter chart is displayed
Problem 4. Add a title to a chart.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2], [3, 4]) plt.title(“Marks”) plt.show()

OUTPUT

a line chart titled Marks
Problem 5. Label the x and y axes.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2], [3, 4]) plt.xlabel(“Day”) plt.ylabel(“Sales”) plt.show()

OUTPUT

a chart with labelled axes
Problem 6. Draw a line in red.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 4, 9], color=”red”) plt.show()

OUTPUT

a red line chart
Problem 7. Draw two lines on one chart.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2, 3], [1, 2, 3]) plt.plot([1, 2, 3], [3, 2, 1]) plt.show()

OUTPUT

two lines on one chart
Problem 8. Add a legend.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2], [1, 2], label=”A”) plt.legend() plt.show()

OUTPUT

a chart with a legend for A
Problem 9. Plot marks of three students as bars.

SOLUTION

import matplotlib.pyplot as plt plt.bar([“Ravi”, “Sana”, “Omar”], [82, 91, 76]) plt.title(“Marks”) plt.show()

OUTPUT

a bar chart of student marks
Problem 10. Plot the numbers 1 to 5 as a line.

SOLUTION

import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4, 5]) plt.show()

OUTPUT

a rising line from 1 to 5

Practice set A, multiple choice

1. Which function draws a line chart?

plt.plot().

2. Which draws a bar chart?

plt.bar().

3. Which adds a title?

plt.title().

4. Which displays the chart?

plt.show().

Quick summary

Matplotlib draws charts in Python. plt.plot() draws a line chart, plt.bar() a bar chart and plt.scatter() a scatter chart; plt.show() displays it. plt.title(), plt.xlabel(), plt.ylabel() and plt.legend() label a chart. Line charts show change, bar charts compare groups, and scatter charts show a link between two values.

Open the Virtual Lab

These free Class 12 Informatics Practices notes explain plotting data with Matplotlib, line bar and scatter charts, adding titles and labels, and choosing the right chart with clear examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 12 Informatics Practices syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories