Creating line graphs in Python

Line Graphs are used to represent simple information in X-axis and Y-axis. Like, for an example, an international cricket batsmen scores over span of last five years can be drawn in a graph which indicates his form.

--------------------------------------

To draw graphs and any visualizations matplotlib is used. Install matplotlib using pip


--------------------------------------

Below is a simple example to create a linear graph showing runs scored by an international cricketer in last 5 years

import matplotlib.pyplot as plotdata

#create lists of data to be displayed
years = ["2017","2018","2019","2020","2021"]
runs = [1200,960,1450,1240,340]

#create line graph with desired axis
plotdata.plot(years,runs,'brown')

#set the title of the graph
plotdata.title('Player A International score')
plotdata.xlabel('Years')
plotdata.ylabel('Runs')

plotdata.show()

The output shall be:


------------------------

The above code is described in the below video:


Post a Comment

0 Comments