Python Practical 2
Python Practical 2
Bar graph
x=["M1","M2","E1","E2"]
y=[25,30,14,20]
xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,color=['r','g','cyan','m'])
show()
Output:
Q
x=["M1","M2","E1","E2"]
y=[25,30,14,20]
tick_label=['M1','M2','E1','E2']
xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m'],edgecolor='k',width=0.5,ls='dotted')
show()
Exercise:
x=['Physics','Chemistry','Maths','Bio']
y=[48,53,51,64]
xlabel("Subject",c='r',fontsize=10)
ylabel("Marks",c='g',fontsize=10)
title("Result")
bar(x,y,color=['r','g','cyan','m'],edgecolor='k',width=0.5,ls='--')
show()
Output:
Que 2
x=[15,25,35,45]
y=[20,45,25,10]
tick_label=['15','25','35','45']
xlabel("Savings",c='r',fontsize=10)
ylabel("No of employees",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m'],edgecolor='k',width=5,ls='--')
show()
Output:
Que 3
x=['Cricket','Football','Badminton','Hockey','Other']
y=[34,50,24,10,82]
tick_label=['Cricket','Football','Badminton','Hockey','Other']
xlabel("Sports",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m','k'],edgecolor='k',width=0.9,ls='--')
show()
Output:
Que 4
x=['Singing','Reading Books','Dancing','Painting','Others']
y=[34,50,24,10,82]
tick_label=['Singing','Reading Books','Dancing','Painting','Other']
xlabel("Hobbies",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Result")
bar(x,y,tick_label=tick_label,color=['r','g','cyan','m','k'],edgecolor='k',width=0.9,ls='--')
show()
Output:
Histogram:
Q1
x=[5,23,15,46,73,89,45,78,36,92,88,84,96,76,11,65,49]
bins=5
xlabel("Age group",c='r',fontsize=10)
ylabel("No of peoples",c='g',fontsize=10)
title("Age group histogram")
hist(x,bins,histtype='bar',edgecolor='k')
show()
Output:
Q2
x=[134,152,136,142,148,150,154]
bins=4
xlabel("Height(in cm)",c='r',fontsize=10)
ylabel("No of students",c='g',fontsize=10)
title("Age group histogram")
hist(x,bins,histtype='bar',color='cyan',edgecolor='k')
show()
Output:
Q3
from matplotlib.pyplot import*
from numpy import*
x=[11,12,13,14,27,48,51,56,49,20,22,29,30,36,37]
bins=5
xlabel("Age group",c='r',fontsize=10)
ylabel("No of illiterates",c='g',fontsize=10)
title("Illeterate persons")
hist(x,bins,histtype='bar',color='cyan',edgecolor='k')
show()
Output: