KnowledgeBoat Logo
LoginJOIN NOW

Informatics Practices

Write a Python program to display a horizontal bar chart of the number of students in a class.

Sample data:

Class: I, II, III, IV, V, VI, VII, VIII, IX, X
Strengths: 40, 43, 45, 47, 49, 38, 50, 37, 43, 39

PyPlot

1 Like

Answer

import matplotlib.pyplot as plt
classes = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X']
strengths = [40, 43, 45, 47, 49, 38, 50, 37, 43, 39]
plt.barh(classes, strengths)
plt.title('Number of Students in Each Class')
plt.xlabel('Number of Students')
plt.ylabel('Class')
plt.show()
Output
Write a Python program to display a horizontal bar chart of the number of students in a class. Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12

Answered By

2 Likes


Related Questions