CBSE Class 12 · Informatics Practices, code 065 · Data visualization

Class 12 IP data visualization: three plots, drawn, saved and read.

Data visualization in Class 12 IP is a short chapter with an honest reward: one four-mark program whose lines you can know in advance. The syllabus has only a line plot, a bar graph and a histogram. Below, each is drawn from fresh data, the picture is the very file the code saved, and beside every chart is the sentence it lets you say.

Live one to one · seven real charts with their code · four-mark answer marked · hours of your choice

Start here

Courses where charts have something to say

A chart is only as good as the table under it. These courses keep the two together, beginning with the board subject.

Ans. The short version

Class 12 IP data visualization (CBSE 065) is the part of Unit 1 where you show data as pictures using Matplotlib. The 2026-27 syllabus has three plots: line plot with plt.plot(), bar graph with plt.bar() and histogram with plt.hist(), customised by a title, axis labels and a legend, and saved with plt.savefig(). The sample paper asks a four-mark line graph program. Modern Age Coders teaches this live, personalised one to one, on your own timetable; a priority demo is a full class you can try before enrolling.

A. Before any code

What is data visualization, and which plot should you use?

Data visualization means showing data as charts so that a change, a comparison or a pattern can be seen without reading every number. Its purpose is to help people draw conclusions.

Your dataThe questionPlotFunction
Values in an order: days, weeks, monthsHow did it change?Line plotplt.plot(x, y)
One value for each named thingWhich is more, which is less?Bar graphplt.bar(names, values)
One long list of numbersHow are they spread?Histogramplt.hist(values, bins=...)

Data visualization Class 12 notes: every function you need

FunctionWhat it doesA slip and its result
import matplotlib.pyplot as pltBrings in the plotting functionsimport matplotlib as plt, then plt.plot: AttributeError
plt.title("...")Heading above the chartCalled twice, the second replaces the first
plt.xlabel("..."), plt.ylabel("...")Names the axes, with unitsplt.xlable: AttributeError
label="..." inside the plot callNames one line or one set of barsWithout legend() it is never shown
plt.legend()Draws the box that lists the labelsWith no label given: a warning and an empty box
plt.savefig("a.png")Saves the figure; PNG and PDF both workAn unknown ending such as .xyz: ValueError
plt.show()Displays the figureForgotten in the paper: half a mark

Save first, show after. When a figure is closed, the next savefig() starts a new, empty one. We closed a figure and then saved: the file was a plain white image.

B. Change over an order

How do you draw a line plot in Matplotlib for Class 12 IP?

Give plt.plot() two lists of equal length, x first and y second, then add the title, the axis labels and, if there is more than one line, a legend.

One lineMatplotlib
import matplotlib.pyplot as plt

day = [0, 3, 6, 9, 12, 15]
height = [0, 1.5, 4, 8.5, 13, 16]

plt.figure(figsize=(8, 5))             # size in inches
plt.plot(day, height)
plt.title("Height of one bean seedling")
plt.xlabel("Day")
plt.ylabel("Height (cm)")
plt.savefig("01-line-seedling.png", dpi=150)
plt.show()
The chart01-line-seedling.png
Line chart of the height of one bean seedling, rising from 0 to 16 cm in 15 days and steepest between day 6 and day 12

Read it: growth is slow until day 3, quickest from day 6 to day 12, and a little slower at the end.

Two lines, so a legendMatplotlib
import matplotlib.pyplot as plt

day = [0, 3, 6, 9, 12, 15]
compost = [0, 1.5, 4, 8.5, 13, 16]
plain = [0, 1.5, 3.5, 6, 8, 9.5]

plt.figure(figsize=(8, 5))
plt.plot(day, compost, color="seagreen", marker="o",
         label="With compost")
plt.plot(day, plain, color="sienna", marker="s",
         linestyle="--", label="Plain soil")
plt.title("Bean seedlings in two kinds of soil")
plt.xlabel("Day")
plt.ylabel("Height (cm)")
plt.legend()
plt.savefig("02-line-two-soils.png", dpi=150)
plt.show()
The chart02-line-two-soils.png
Two lines of seedling height, solid green with compost ending at 16 cm and dashed brown in plain soil ending at 9.5 cm, with a legend at top left

Read it: both are equal till day 3. By day 15 the compost seedling is 6.5 cm taller.

Two plot() calls before one show() share the same axes. The colour, marker and linestyle are extras: the syllabus asks for label, title and legend. If the lists differ in length, Matplotlib stops with ValueError. If you pass one list, it becomes y, and x is 0, 1, 2 and so on.

C. Comparing named things

Bar graph program for Class 12 IP, from lists and from a CSV file

plt.bar() takes the names for the x-axis first and the heights second. The bars stand apart because the names are separate categories.

From two listsMatplotlib
import matplotlib.pyplot as plt

classes = ["VI", "VII", "VIII", "IX", "X"]
paper_kg = [46, 38, 52, 27, 33]

plt.figure(figsize=(8, 5))
plt.bar(classes, paper_kg, width=0.6, color="seagreen",
        label="Waste paper")
plt.title("Waste paper collected for recycling")
plt.xlabel("Class")
plt.ylabel("Paper (kg)")
plt.legend()
plt.savefig("03-bar-paper.png", dpi=150)
plt.show()
The chart03-bar-paper.png
Bar graph of waste paper collected by classes VI to X: 46, 38, 52, 27 and 33 kg

Read it: class VIII collected the most, 52 kg, and class IX the least, 27 kg.

From a CSV fileMatplotlib
import pandas as pd
import matplotlib.pyplot as plt

drive = pd.DataFrame([
    {"Class": "VI", "Kg": 46, "Students": 40},
    {"Class": "VII", "Kg": 38, "Students": 38},
    {"Class": "VIII", "Kg": 52, "Students": 52},
    {"Class": "IX", "Kg": 27, "Students": 18},
    {"Class": "X", "Kg": 33, "Students": 30}])
drive.to_csv("drive.csv", index=False)

drive = pd.read_csv("drive.csv")           # as in the lab
drive["Each"] = drive["Kg"] / drive["Students"]
print(drive)

plt.figure(figsize=(8, 5))
plt.bar(drive["Class"], drive["Each"], color="sienna")
plt.title("Waste paper per student")
plt.xlabel("Class")
plt.ylabel("Paper per student (kg)")
plt.savefig("04-bar-per-student.png", dpi=150)
plt.show()
The chart04-bar-per-student.png
Bar graph of waste paper per student: VI 1.15, VII 1.0, VIII 1.0, IX 1.5 and X 1.1 kg

Read it: class IX, last in the first chart, is first per student.

Also printedtext
  Class  Kg  Students  Each
0    VI  46        40  1.15
1   VII  38        38  1.00
2  VIII  52        52  1.00
3    IX  27        18  1.50
4     X  33        30  1.10

The two charts use one table and give opposite winners. Suggested practical 5.2 asks you to analyse a DataFrame and plot it with a title and legend, and a new column is often where the analysis is. width is 0.8 when you do not give it.

D. How values are spread

What is a histogram in Class 12 IP, and how is it different from a bar graph?

A histogram groups one list of numbers into ranges called bins and draws a bar as tall as the number of values in each bin. A bar graph compares separate names; a histogram shows the spread of one quantity.

Bins chosen by youMatplotlib
import matplotlib.pyplot as plt

grams = [182, 190, 205, 211, 214, 218, 222, 225, 226, 231,
         233, 235, 238, 240, 241, 244, 247, 252, 255, 258,
         263, 268, 274, 280, 291]
edges = [180, 200, 220, 240, 260, 280, 300]

plt.figure(figsize=(8, 5))
result = plt.hist(grams, bins=edges, color="seagreen",
                  edgecolor="black")
print(result[0])               # how many in each bin
plt.title("Weights of 25 mangoes from one tree")
plt.xlabel("Weight (g)")
plt.ylabel("Number of mangoes")
plt.savefig("05-hist-mangoes.png", dpi=150)
plt.show()
The chart05-hist-mangoes.png
Histogram of 25 mango weights in six 20-gram bins with bars of 2, 4, 7, 7, 3 and 2

Read it: 14 of the 25 mangoes weigh from 220 g to just under 260 g.

Also printedtext
[2. 4. 7. 7. 3. 2.]

Sort the same list by hand

BinValues that fall in itCount
180 to below 200182, 1902
200 to below 220205, 211, 214, 2184
220 to below 240222, 225, 226, 231, 233, 235, 2387
240 to below 260240, 241, 244, 247, 252, 255, 2587
260 to below 280263, 268, 2743
280 to 300280, 2912

240 and 280 sit on an edge and go to the bin on their right. Only the last bin includes both ends. A value outside all the edges is left out without any message, so check that the counts add up to the size of the list: here, 25.

Bins given as a numberMatplotlib
import matplotlib.pyplot as plt

grams = [182, 190, 205, 211, 214, 218, 222, 225, 226, 231,
         233, 235, 238, 240, 241, 244, 247, 252, 255, 258,
         263, 268, 274, 280, 291]

plt.figure(figsize=(8, 5))
result = plt.hist(grams, bins=3, color="sienna",
                  edgecolor="black")
print(result[0])
print(result[1])               # the edges it chose
plt.title("The same mangoes in three bins")
plt.xlabel("Weight (g)")
plt.ylabel("Number of mangoes")
plt.savefig("06-hist-three-bins.png", dpi=150)
plt.show()
The chart06-hist-three-bins.png
The same 25 mango weights in three wide bins with bars of 6, 12 and 7

Read it: the middle is still tallest, but the detail has gone. With bins left out, Matplotlib uses 10.

Also printedtext
[ 6. 12.  7.]
[182.         218.33333333 254.66666667 291.        ]

Bar graph and histogram compared

PointBar graphHistogram
DataNames and a value for eachOne list of numbers
x-axisSeparate categoriesA continuous scale cut into bins
Height of a barThe value itselfHow many values fall in the bin
GapsBars stand apartBars touch
Order of barsCan be changedFixed by the number scale
ExampleKilograms from each classWeights of 25 mangoes

E. In the answer book

Matplotlib Class 12 IP questions: the four-mark program and the rest

The 2026-27 scheme gives 1 mark for the import, 1 for plot() with the label and half a mark each for title, axis labels, legend and show(). Data for an original one: skips in a minute over five weeks.

Four marks, line by lineMatplotlib
import matplotlib.pyplot as plt                     # 1 mark

week = ["W1", "W2", "W3", "W4", "W5"]
skips = [42, 55, 51, 68, 74]

plt.figure(figsize=(8, 5))
plt.plot(week, skips, marker="o", label="Skips")    # 1
plt.title("Rope skipping practice")                 # 1/2
plt.xlabel("Week")
plt.ylabel("Skips in a minute")                     # 1/2
plt.legend()                                        # 1/2
plt.savefig("07-line-skips.png", dpi=150)
plt.show()                                          # 1/2
The chart07-line-skips.png
Line chart of skips in a minute over five weeks: 42, 55, 51, 68 and 74

The figure() and savefig() lines are for the computer. In the paper, write them only if you are asked to set a size or save. The y-axis does not begin at 0, so read the numbers and not only the slope.

One mark

  1. Which function names the horizontal axis?
    Answer plt.xlabel()
  2. Fill in: to show the labels of two lines in a box, call plt.______().
    Answer legend
  3. Which argument of hist() decides the number of ranges?
    Answer bins
  4. Which plot suits the rainfall of twelve months in order, and which suits the heights of 60 students?
    Answer A line plot for the first, a histogram for the second.
  5. What is the first argument of plt.bar(a, b) used for?
    Answer The categories along the x-axis. b gives the heights.
  6. Name the statement that keeps a chart as the file trend.png.
    Answer plt.savefig("trend.png")
  7. Assertion: In a histogram of 40 values, the heights of the bars add up to 40 if every value lies within the bins. Reason: Each bar shows the number of values in its bin.
    Answer Both are true and R explains A.
  8. hist() is given the values 200, 220 and 240 with edges 180, 200, 220, 240. What are the three counts?
    Answer 0, 1, 2. 200 goes to the second bin, 220 to the third, and 240 also to the third, because the last bin includes its end.

Two marks

  1. What is the purpose of a legend? When is it needed?
    Answer It tells which colour or style stands for which set of data. It is needed as soon as a chart has more than one line or set of bars.
  2. Give two differences between a bar graph and a histogram.
    Answer Any two rows of the table above, such as: a bar graph has separate categories and the height is the value; a histogram has number ranges and the height is a count.
  3. State the purpose of data visualization with one example.
    Answer To see patterns and comparisons quickly. Example: a line of monthly sales shows the month of the fall at once.

Find five errors

Wrong on purposea bar graph
import matplotlib as plt
fruit = ["Guava", "Papaya", "Chikoo"]
sold = [25, 18]
plt.bar(fruit, sold, label="Sold")
plt.Title("Fruit sold on Monday")
plt.xlable("Fruit")
plt.legend
plt.show()
Corrections import matplotlib.pyplot as plt; a third value in sold; plt.title with a small t; plt.xlabel; and round brackets after legend. The last slip gives no error: the box is simply missing.

Write it yourself

  1. Plot a bar graph of the buses on five routes: R1 4, R2 7, R3 3, R4 6, R5 5. Give a title, both labels and save it as routes.png. (4 marks)
    Answer Import; plt.bar(["R1", "R2", "R3", "R4", "R5"], [4, 7, 3, 6, 5]); title; xlabel and ylabel; plt.savefig("routes.png"); show.
  2. The column Minutes of a DataFrame d holds the time 50 people spent in a museum. Draw a histogram with bins of 15 minutes from 0 to 90. (3 marks)
    Answer plt.hist(d["Minutes"], bins=[0, 15, 30, 45, 60, 75, 90]) with labels Minutes and Number of people.
  3. Change the two-line program above so that a third seedling, kept in shade, is added.
    Answer One more list of six heights, one more plt.plot() with its own label before plt.legend(). Nothing else changes.

For the practical

The file needs at least four Matplotlib programs, and a viva can start at a chart: why this plot, why these bins, what does the fall in week three mean? A complete set with output is in the Class 12 IP practical file, and spoken answers are in IP viva questions.

Sketch before code

The student draws the expected chart roughly on paper. A wrong choice of plot is noticed there, and not after ten lines of typing.

One sentence each

No chart is finished until the student has said what it shows, with a number in the sentence.

Six lines from memory

Import, plot, title, labels, legend, show: written by hand for a new set of data at the start of class until it is automatic.

Charts usually begin with a table, so revise DataFrames and Series beside this page. For a full project built on charts see the IP project with source code.

One to one, at your own timing

Charts taught by someone who asks what they mean

Typing plt.bar is quick. Explaining why it should have been plt.hist takes a conversation, and that is what a personalised one to one class is. You decide the days and the time. To see one, take a priority demo: it is a paid full class, and if you enrol the amount is counted in the first month. Or take the free demo class. We bill month by month, there is no admission fee, and you are free to stop when a month ends.

Before you enrol · Try a class

Priority demo, at a slot you pick

a full live class of about 45 to 60 minutes

  • You pick the right plot for three small sets of data and defend it
  • A four-mark program is written by hand and marked in halves
  • The chart is drawn and saved from your own laptop
  • A written report tells you which steps were missing
Book a priority demo

The classes · Choose your own timing

Personalised one to one

₹4,999

per month, 4 private classes, fully flexible timing

  • Line, bar and histogram until each is written from memory
  • pandas repaired on the way, since most charts start in a table
  • Your file and project charts discussed, drawn by you
  • Chart reading in full sentences for the viva and the report
Ask for a personalised plan

Data visualization can be finished in a few classes, so the rest of the month can go to SQL or DataFrames. What a month costs is printed on this page in your own currency.

Studying outside India?

Matplotlib lessons for 065 students overseas

CBSE schools in Riyadh, Doha and Singapore use the same three plots. Choose a time that falls after your school and before your dinner.

Where you liveTime differenceUsual class window, local timeFormat
India
every Indian city
Indian timeAny time you choosePersonalised 1-on-1
UAE and Oman
Dubai, Abu Dhabi, Sharjah, Muscat
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Saudi Arabia, Qatar, Kuwait, Bahrain
Riyadh, Jeddah, Dammam, Doha, Kuwait City, Manama
2 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Nepal
Kathmandu
15 min ahead of India4:30 PM to 9:00 PMPersonalised 1-on-1
Ethiopia and East Africa
Addis Ababa and East Africa Time
2 h 30 min behind India4:30 PM to 9:00 PMPersonalised 1-on-1
Singapore and Malaysia
Singapore, Kuala Lumpur
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

You need Python with pandas and Matplotlib. Installation trouble is common, so mention it when you book and the first class starts there.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 12 series

More pages for Class 12 students

Every page in the CBSE Class 12 Informatics Practices series, grouped by what you need.

Questions about charts

Data visualization in Class 12 IP: what students ask

What is data visualization in Class 12 IP?

Data visualization is the representation of data in the form of charts and graphs. In CBSE Informatics Practices 065 it is part of Unit 1 and is done with the Matplotlib library in Python. Its main purpose is to show trends, comparisons and the spread of values so that a reader can draw conclusions easily.

Which plots are in the Class 12 IP syllabus 2026-27?

Three: line plot, bar graph and histogram. The syllabus also lists drawing and saving these plots, and customising them by adding a label, a title and a legend. Pie charts, scatter plots and box plots are not on the Class XII list for this session.

What is Matplotlib and pyplot?

Matplotlib is a Python library for drawing charts. pyplot is the module inside it that has simple functions such as plot(), bar(), hist(), title() and show(). It is imported with import matplotlib.pyplot as plt, and plt is only the usual short name.

What is the difference between a bar graph and a histogram?

A bar graph compares separate categories, and each bar shows the value of one category. A histogram shows how one set of numbers is distributed: the x-axis is divided into ranges called bins and each bar shows how many values fall inside. The bars of a histogram touch each other.

What are bins in a histogram?

Bins are the ranges into which the values are grouped. bins=3 asks for three equal ranges between the smallest and largest value. A list such as [180, 200, 220] sets the edges yourself. Each bin includes its left edge and not its right one, except the last bin, which includes both.

How do I add a legend in Matplotlib?

Give each plot a label, as in plt.plot(x, y, label="Sales"), and then call plt.legend() once before plt.show(). A label without legend() is not displayed, and legend() without any label shows an empty box and a warning.

How do I save a chart in Python for my practical file?

Call plt.savefig("chart.png") before plt.show(). You may add dpi=150 for a sharper picture, and a name ending in .pdf also works. If you save after the figure has been closed, the file is blank.

How many marks does data visualization have in Class 12 IP?

It shares 25 marks with pandas. In the 2026-27 sample paper, Question 4 (1 mark), Question 24 (2 marks) and Question 33 (4 marks) are on this topic, which makes 7. In the practical, pandas and Matplotlib programs together carry 8 of the 30 marks.

How do I plot a DataFrame column?

Pass the columns to the plotting function: plt.bar(drive["Class"], drive["Kg"]) or plt.hist(d["Minutes"]). A column is a Series, and Matplotlib accepts it like a list. Import both pandas and matplotlib.pyplot at the top.

Are colour, marker and linestyle needed in the board exam?

Write them only when the question asks. The official scheme for the line graph gives marks for import, plot with label, title, axis labels, legend and show. Extras are not in that scheme, so finish the listed lines first.

Why does my Matplotlib program show no chart?

In a script, check that plt.show() is there with its brackets. Check the import line too, since import matplotlib alone does not give you plot(). If the window opens and is empty, the plot call probably came after show().

Can I learn Matplotlib one to one for Class 12 IP?

Yes. The class is live, for one student, at the time you choose, and you draw every chart yourself. Try a priority demo of about 45 to 60 minutes first, with a written skill report after it and the fee adjusted in your first month if you enrol, or take a free demo class.

Start

Turn one list of numbers into a chart

Come to the free demo class with any numbers you find interesting: cricket scores, bus timings, pocket money. Choosing the plot for them is the first exercise.

A priority demo covers more ground. You choose the slot, draw all three plots from new data, write the four-mark program by hand, and get a written skill report; the demo fee is adjusted against the first month if you go on.

More topics for a longer piece of work are on Class 12 IP project topics.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here