Jawahar Education Society's
A.C. Patil College of Engineering Kharghar
Department: Electrical Engineering
EXPERIMENT NO.09
AIM: TO WRITE A PROGRAM FOR SIMPLE PLOT USING MATPLOTLIB
Matplotlib is a Python library that helps in visualizing and analyzing the data and helps in better understanding of the data with the help of
graphical, pictorial visualizations that can be simulated using the matplotlib library. Matplotlib is a comprehensive library for static, animated
and interactive visualizations.
Installation of matplotlib library
Step 1: Open command manager (just type “cmd” in your windows start search bar)
Step 2: Type the below command in the terminal.
cd Desktop
Step 3: Then type the following command.
pip install matplotlib
Creating a Simple Plot
Jawahar Education Society's
A.C. Patil College of Engineering Kharghar
Department: Electrical Engineering
Output
The code seems self-explanatory. Following steps were followed:
Define the x-axis and corresponding y-axis values as lists.
Plot them on canvas using .plot() function.
Give a name to x-axis and y-axis using .xlabel() and .ylabel() functions.
Give a title to your plot using .title() function.
Finally, to view your plot, we use .show() function.
Method Description
It creates the plot at the background of computer, it doesn’t displays it. We can also add a label as it’s argument that by
plot()
what name we will call this plot – utilized in legend()
show() It displays the created plots
xlabel() It labels the x-axis
ylabel() It labels the y-axis
title() It gives the title to the graph
gca() It helps to get access over the all the four axes of the graph
xticks() It decides how the markings are to be made on the x-axis
yticks() It decides how the markings are to be made on the y-axis
Pass a list as it’s arguments of all the plots made, if labels are not explicitly specified then add the values in the list in the
gca().legend()
same order as the plots are made
annotate() It is use to write comments on the graph at the specified position