Page 268 - Robotics and AI class 10
P. 268
15. Creating a normal distribution and displaying in graph (using Numpy + Matplotlib) - Display the scores of
students in a graph and check if it is a normal distribution? What is the mean, median and mode of this data?
Ans. import numpy as np
import matplotlib.pyplot as plt
scores = np.array([75, 82, 88, 92, 68, 78, 85, 90, 95, 98])
# Calculate mean and standard deviation
mean_score = np.mean(scores)
std_dev = np.std(scores)
# Create a histogram of the scores with a normal distribution curve
plt.figure(figsize=(10, 6))
plt.hist(scores, bins=5, density=True, alpha=0.6, color='blue', label='Histogram')
plt.title('Student Scores Distribution')
plt.xlabel('Score')
plt.ylabel('Density')
plt.grid(True)
# Create the normal distribution curve
x_range = np.linspace(min(scores), max(scores), 100)
normal_distribution = (1 / (std_dev * np.sqrt(2 * np.pi))) * np.exp(-((x_range
- mean_score)**2) / (2 * std_dev**2))
plt.plot(x_range, normal_distribution, color='red', label='Normal Distribution')
plt.legend()
plt.show()
Output:
266 Touchpad Robotics & Artificial Intelligence-X

