Skip to main content

Matplotlib: Create a simple plot

Matplotlib is a library in python that helps us to visualise the data graphically. pyplot is a module of Matplotlib which provides MATLAB-like interface. To begin with plotting the graph

Firstly we need to import required libraries.

import matplotlib.pyplot as plt 
import numpy as np

Then we will define two parameter as an array which is containing points of x and y axis.


The plot() function is used to plot the points in a diagram, and then draw line from point to point. 

# plotting the points  
plt.plot(x, y)

Give the label to x-axis and y-axis using .xlabel() and .ylabel() functions. You can also give title to your graph using title() functions.

# naming the x axis 
plt.xlabel('x - axis') 
# naming the y axis 
plt.ylabel('y - axis') 

Finally use show() function to view the graph.


First plot

Submitted by devanshi.srivastava on November 22, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.