Informatics Practices

Introduction to Data Visualization using Matplotlib | Complete Notes | CBSE Class 12 Informatics Practices (2026–27)

Class 12 · Informatics Practices

Introduction to Data Visualization using Matplotlib

Large amounts of numerical data are often difficult to understand by looking at tables alone. Data Visualization helps represent data in the form of graphs and charts, making it easier to identify trends, patterns, and comparisons.

In Python, the Matplotlib library is used to create different types of graphs. It is one of the most popular data visualization libraries and is included in the CBSE Class 12 Informatics Practices syllabus.


What is Data Visualization?

Definition

Data Visualization is the graphical representation of data using charts, graphs, and plots to make information easier to understand and analyze.


Why is Data Visualization Important?

  • Makes complex data easy to understand.
  • Shows trends and patterns clearly.
  • Helps compare different values.
  • Supports better decision-making.
  • Makes reports more attractive and meaningful.

Real-Life Applications

Field Example
Education Student performance analysis
Business Monthly sales reports
Healthcare Patient statistics
Sports Player performance comparison
Weather Temperature analysis
Finance Stock market trends

What is Matplotlib?

Definition

Matplotlib is an open-source Python library used for creating graphs, charts, and plots from numerical data.


Features of Matplotlib

  • Simple and easy to use.
  • Creates high-quality graphs.
  • Supports many chart types.
  • Allows customization of plots.
  • Works well with Pandas DataFrames.
  • Widely used in Data Science and Machine Learning.

Types of Graphs in the CBSE Syllabus

Graph Purpose
Line Plot Shows trends over time.
Bar Graph Compares different categories.
Histogram Shows frequency distribution.

The pyplot Module

Most plotting functions are available in the pyplot module of Matplotlib.

Import Statement

import matplotlib.pyplot as plt

Explanation

  • matplotlib → Library name
  • pyplot → Plotting module
  • plt → Standard alias

Basic Steps to Draw a Graph


Import matplotlib

↓

Prepare Data

↓

Create Plot

↓

Customize Plot

↓

Display Plot


General Syntax

import matplotlib.pyplot as plt

# Plot Command

plt.show()

The show() function displays the graph on the screen.


Example

import matplotlib.pyplot as plt

x = [1,2,3]
y = [5,7,9]

plt.plot(x,y)

plt.show()

This program creates and displays a simple line graph.


Saving a Plot

Graphs can be saved as image files using the savefig() function.

Syntax

plt.savefig("graph.png")

The graph is saved in the current working directory.


Common Image Formats

Extension Format
.png Portable Network Graphics
.jpg JPEG Image
.pdf Portable Document Format
.svg Scalable Vector Graphics

Matplotlib Workflow


Prepare Data

↓

Import pyplot

↓

Create Plot

↓

Customize Plot

↓

Save (Optional)

↓

Display


Advantages of Data Visualization

  • Easy interpretation of data.
  • Quick identification of trends.
  • Better comparison of values.
  • Professional presentation of reports.
  • Useful for research and analysis.

Common Errors

Error Reason
ModuleNotFoundError Matplotlib is not installed.
NameError Alias plt not defined.
ValueError X and Y data lengths are different.
Blank Graph plt.show() not called.

Quick Revision

Concept Remember
Data Visualization Graphical representation of data
Matplotlib Python plotting library
pyplot Module used for plotting
plt Standard alias
show() Displays graph
savefig() Saves graph

CBSE Exam Tips

  • Remember the import statement exactly:
    import matplotlib.pyplot as plt
  • Know the purpose of show() and savefig().
  • Remember the three graphs in the syllabus:
    • Line Plot
    • Bar Graph
    • Histogram
  • Understand why graphs are preferred over tables for large datasets.
  • Practice identifying the appropriate graph for different situations.

Summary

Data Visualization converts numerical data into meaningful graphs that are easier to understand and analyze. The Matplotlib library provides powerful plotting tools through the pyplot module. Functions such as show() and savefig() help display and save graphs, making Matplotlib an essential tool for data analysis and reporting.