Q. Consider the data given below create a sequence required from the data below :-

Write code to :
(a) Create bar chart to see distribution of rainfall from jan – dec for all the zones .
(b) Create a pie chart to check the amount of rainfall in jan separately .
(c) Create a line chart to observe any trends from jan to dec .


You can understand by Watching video :-



Answer :-

(a)

import matplotlib.pyplot  as p
import numpy as n

jan= [140,160,140,180,110]
feb= [130,200,180,150,160]
mar = [130,130,150,200,130]
apr = [190,200,170,120,110]
may = [160,200,190,180,120]
jun = [200,170,140,140,170]
jul = [150,110,170,110,130]
aug = [170,160,180,130,200]
sep= [190,130,190,150,150]
oct = [170,140,150,190,160]
nov= [150,170,140,110,170]
dec = [120,200,170,140,130]

con= ["North","South","East","West","Central"]
b = n. arange( 20 , 110 ,20)
p.title("Rain fall data ")
p.ylabel("Rain in mm ")
p.xlabel("Zones")
p.xlim(0,120)
p.bar(b+0.0 , jan,width=1.0 , label= "jan",color = "r")
p.bar(b + 1 , feb,width=1.0, label= "feb",color = "y")
p.bar(b + 2 , mar,width=1.0, label= "mar",color = "b")
p.bar(b + 3 , apr,width=1.0, label= "apr",color = "g")
p.bar(b + 4 , may,width=1.0, label= "may",color = "c")
p.bar(b + 5 , jun,width=1.0, label= "jun",color = "k")
p.bar(b + 6 , jul,width=1.0, label= "jul",color = "m")
p.bar(b + 7 , aug,width=1.0, label= "aug",color = "pink")
p.bar(b + 8 , sep,width=1.0, label= "sep",color = "orange")
p.bar(b + 9 , oct,width=1.0, label= "oct",color = "brown")
p.bar(b + 10 , nov,width=1.0, label= "nov",color = "gray")
p.bar(b + 11 , dec,width=1.0, label= "dec",color = "purple")
p.legend (loc= "upper left")
p.xticks(b+6,con)
p . show()

(b)

import matplotlib.pyplot  as p

jan= [140,160,140,180,110]

p.title("Portal Express")
con= ["North","South","East","West","Central"]
p.pie(jan,labels=con,autopct="%1.1f%%")

p . show()

(c)

import matplotlib.pyplot  as p
import numpy as n
b = n.arange(12)
North =  [140,130,130,190,160,200,150,170,190,170,150,120]
South = [160,200,130,200,200,170,110,160,130,140,170,200]
East = [140,180,150,170,190,140,170,180,190,150,140,170]
West = [180,150,200,120,180,140,110,130,150,190,110,140]
Central = [110,160,130,110,120,170,130,200,150,160,170,130]

p.plot(b,North,color = 'r', label = 'North')
p.plot(b,South,color = 'b', label = 'South')
p.plot(b,East,color = 'g', label = 'East')
p.plot(b,West,color = 'y', label = 'West')
p.plot(b,Central,color = 'k', label = 'Central')
p.legend(loc='upper left')
p.xticks(b,['jan','feb','mar','apr','may','jun','jul','aug','sept','oct','nov','dec'])
p.xlabel("Months")
p.ylabel("Rainfall in mm")
p.show()


Output :-

(a)


(b)


(c)




2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post