Skip to content

Write a Python program to display a BAR CHART of the number of students in a school.

Write a Python program to display a BAR CHART of the number of students in a school.

SOLUTION

Create a Bar Chart…….

import matplotlib.pyplot as plt

groups = ['I', 'II', 'III', 'IV']
strength = [38, 30, 45, 49]

# provide different colors for each bar (one color per bar)
colors = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red']  # matplotlib default color cycle

plt.figure(figsize=(7,4))
plt.bar(groups, strength, color=colors)
plt.xlabel('Groups')
plt.ylabel('Number of Students')
plt.title('Group wise Students')
plt.grid(True, axis='y', linestyle='--', linewidth=0.5)
plt.show()