KnowledgeBoat Logo
|

Informatics Practices

Write a Python program to display a bar chart of the number of students in a class. Use different colors for each bar.

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

4 Likes

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.bar(classes, strengths, color=['red', 'green', 'blue', 'yellow', 'orange', 'purple', 'pink', 'brown', 'gray', 'black'])
plt.title('Number of Students in Each Class')
plt.xlabel('Class')
plt.ylabel('Number of Students')
plt.show()
Output
Write a Python program to display a bar chart of the number of students in a class. Use different colors for each bar. Data Visualization using Matplotlib, Informatics Practices Preeti Arora Solutions CBSE Class 12

Answered By

4 Likes


Related Questions