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

Answered By
2 Likes
Related Questions
Write a Python program to plot two or more lines and set the line markers.
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, 39Plot a line graph for: y2 = 4*x
Write a Python program to plot the function y = x2 using the Matplotlib library.