Page 137 - Informatics_Practices_Fliipbook_Class12
P. 137
14. Collect the minimum and maximum temperature of your city for a month and present it using a histogram plot.
Ans. import matplotlib.pyplot as plt
# Minimum and maximum temperature data
minTemperature = [6, 5, 6, 5, 5, 5, 4, 9, 11, 12, 14, 15, 12, 13, 11, 11, 8, 7, 10, 10,
9, 9, 7, 8, 9, 5, 6, 6, 7, 10]
maxTemperature = [16, 15, 15, 16, 18, 19, 15, 14, 18, 27, 17, 20, 17, 18, 15, 16, 14,
17, 20, 17, 18, 15, 16]
# Plotting histogram
plt.hist([minTemperature, maxTemperature], bins=10, alpha=0.7, label=['Min Temperature',
'Max Temperature'])
# Adding labels and title
plt.xlabel('Temperature (°C)')
plt.ylabel('Frequency')
plt.title('Minimum and Maximum Temperature Histogram')
# Adding legend
plt.legend()
# Display the plot
plt.show()
Output:
Answers
Multiple Choice Questions
1. (b) 2. (a) 3. (c) 4. (d) 5. (d)
True or False
1. (T) 2. (T) 3. (T) 4. (T) 5. (F) 6. (T) 7. (F)
Fill in the blanks
1. color 2. linestyle 3. plt.bar() 4. plt.xlabel() 5. histogram
Data Visualization 123

