Thursday, 11 March 2021

Class 12 IP Practical - 08

 

#8 - Write a program to plot a bar chart from the medals won by the four countries. Make sure that bars are separately visible.                                  

Country

Gold

Silver

Bronze

Total

India

26

20

20

66

Australia

80

59

59

198

England

45

45

46

136

Canada

10

12

14

36

  

import matplotlib.pyplot as plt

import numpy as np

info=['Gold','Silver','Bronze','Total']

India=[26,20,20,66]

Australia=[80,59,59,198]

England=[45,45,46,136]

Canada=[10,12,14,36]

plt.figure(figsize=(10,7))

x=np.arange(len(info))

plt.bar(info,India,width=0.15,label="India")

plt.bar(x+0.15,Australia,width=0.15,label="Australia")

plt.bar(x+0.30,England,width=0.15,label="England")

plt.bar(x+0.45,Canada,width=0.15,label="Canada")

plt.xlabel("Medal Type")

plt.ylabel("Number of Medals won")

plt.title("Medal Tally Bar Chart")

plt.legend()

plt.show()

 





No comments:

Post a comment