Matplotlib
Matplotlib
and represent it in form of bar chart with title to compare an analyze data.
Solution:
Source Code:
import matplotlib.pyplot as plt
medals = [213,224,300,59,100,140,256,98,60,24]
country = ['Ger','Itly','USA','Jamca','Japan',
'India','China','Aus','Arg','Ethopia']
plt.bar(country, medals)
plt.title('Olympics Medal Tally')
plt.show()
Screenshot:
Output
Problem statement: Techtipnow Automobiles is authorized dealer of different Bikescompanies. They record the entire
sale of bikes month wise as give below:
Jan Feb Mar Apr May Jun
Honda 23 45 109 87 95 100
Suzuki 45 57 75 60 50 30
Tvs 97 80 84 68 80 108
To get proper analysis of sale performance create multiple line chart on a common plotwhere all bike sale data
are plotted.
Display appropriate x and y axis labels, legend and chart title.
Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt
d = {'eng':[78,89,90,94],'math':[89,91,80,98],
'phy':[69,84,76,90],'chm':[92,90,82,96],
'IT':[96,98,90,100]}
df = pd.DataFrame(d,[9,10,11,12])
print(df)
df.plot(kind = 'bar',title = 'Class Wise Marks Analysis',
xlabel = 'Class', ylabel = 'Marks')
df1 = df.T
df1.plot(kind = 'bar',title = 'Subject Wise Marks Analysis',
xlabel = 'Class', ylabel = 'Marks')
plt.legend(loc = 'lower center')
plt.show()
Screenshot:
Output
Problem statement: The following seat bookings are the daily records of a month
December from PVR cinemas:
124,124,135,156,128,189,200,150,158, 150,200,124,143,142,130,130, 170,
189,200,130, 142,167,180,143,143, 135,156,150,200,189,189,142
Construct a histogram from above data with 10 bin..
Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt
L = [124,124,135,156,128,189,200,150,158,
150,200,124,143,142,130,130, 170,
189,200,130, 142,167,180,143,143,
135,156,150,200,189,189,142]
plt.hist(L)
plt.title("Booking Records @ PVR")
plt.show()
Screenshot:
Output
Problem statement: Take data of your interest from an open source (e.g. data.gove.in),
aggregate and summarize it. Then plot it using different plotting functions of the Matplotlib
library.
Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('c:\sample\Crime_data.csv')
print(df)
plt.bar(df.Crime,df.Boys,width = 0.25)
plt.bar(0.25,df.Girls,width = 0.25)
plt.bar(0.5,df.Transgender,width = 0.25)
df.plot(kind = 'bar', x = 'Crime')
df.plot(kind = 'bar', x= 'Crime', y= ['Boys','Girls', 'Transgender'])
plt.show()
Screenshot:
Output