Matplotlib in Python
What is Matplotlib
Matplotlib is a low-
level graph plotting
library in python that
serves as a
visualization utility.
Why Do We
Need Graphs?
Visualize Data → Numbers in tables
are hard to compare, but graphs make
trends obvious.
Identify Patterns → Helps spot
increases, decreases, or sudden
changes.
Make Decisions → Graphs simplify
information so people can act on it.
Communicate Results → Easier to
explain research, experiments, or
reports.
Installation
of Matplotlib
Install it using this command:
C:\Users\Your Name>pip install
matplotlib
Checking the Version of
Matplotlib
import matplotlib
print(matplotlib.__version__)
Pyplot
pyplot is a module in Matplotlib, the popular Python
plotting library. It provides a state-machine interface for
creating plots
Import pyplot:
Import [Link] as plt
Matplotlib
Plotting
Matplotlib Functions
Plot() function
The plot() function is used to draw points (markers) in a diagram.
show() function
Allows you to display the output of your program
xlabel and ylabel
sets the label (name) of the x-axis and y-axis.
Title()
sets the title of the graphs
Sample Program
import [Link] as plt #importing library
x=[1,2,3] #values for the two
parameters
y=[2,4,2]
[Link](x,y) #function to plot the
x and y
[Link]() #function to Display the
Graph
Output
import [Link] as
plt
x=[1,2,3]
y=[2,4,2]
[Link](x,y)
[Link]()
Each student records how
Lab 1 ACTIVITY many hours they studied for
the last exam and their score.
Study Hours Exam Score
1 9
2 4
6
3
4 1