Wednesday, January 2, 2019

Four steps to create our first graph using matplotlib

In the field of data science, it is mandatory for us to have an understanding of the graph and we should know how to create one using the python. The idea of this blog is to make you familiar with matplotlib and  help you to  create your first graph.

Python provides us with a library called matplotlib to do the same. It is a plotting library used for 2D graphics in python programming language.

With the help of matplotlib , we can create different types of graphs such as:-

    • Bar Graph
    • Histogram
    • Scatter Plot
    • Area Plot
    • Pie Plot

we will create our first graph using the matplotlib and will move to other graphs in our upcoming blogs.

Step 1:- we need to import the matplotlib library in our python editor.
 
#importing the matplot library

import matplotlib.pyplot as pt


Step 2 :- we need to create the data sets for both the x as well as y axis.


#Creating the data

x = [2,4,6,8,10]

y = [1,2,3,4,5]


Step 3 :- Plotting the data on x as well as y axis .


#plotting the data on x and Y axis

pt.plot(x,y,label='linear')

Step 4 :- Displaying the graph on Python console .

#Displaying the graph

pt.show()


Snippet of the complete program :-


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 28 23:22:00 2018

@author: sangam
"""
#importing the matplot library
import matplotlib.pyplot as pt

#Creating the data
x = [2,4,6,8,10]
y = [1,2,3,4,5]


#plotting the data on x and Y axis
pt.plot(x,y,label='linear')

#Displaying the graph
pt.show()



Output :-





1 comment:

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...