Programs · Program 4-11
Q.(Program 4-11) Plot a frequency polygon for the 'ANNUAL - MIN' column of the "Min/Max Temp" data (file "Min_Max_Seasonal_IMD_2017.csv") over the histogram depicting it.
West Bengal WbchseTextbookSubjective· 3mImportance★★★★★est
32% · 14/44 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Overlay a frequency-polygon line on the minimum-temperature histogram using NumPy's own histogram function.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("Min_Max_Seasonal_IMD_2017.csv", usecols=['ANNUAL - MIN'])
df=pd.DataFrame(data)
minarray=np.array([df['ANNUAL - MIN']])
y,edges = np.histogram(minarray)
mid = 0.5*(edges[1:]+edges[:-1])
df.plot(kind='hist',y='ANNUAL - MIN')
plt.plot(mid,y,'-^')
plt.title('Annual Min Temperature plot(1901 - 2017)')
plt.xlabel('Temperature')
plt.show()
np.histogram() computes the same bin counts/edges the histogram will use; mid (the midpoint of each bin) lets a line with triangle markers ('-^') be overlaid on the bars at their true centre points.
Step by step
np.histogram(minarray)computes the SAME bin edges and counts a histogram bar chart would show, but returns them as plain numbers (y= counts,edges= the 10 bin boundaries) instead of drawing bars.mid = 0.5*(edges[1:]+edges[:-1])finds the midpoint of every bin -- the natural x-position to place a point representing "this bin's count".df.plot(kind='hist', ...)draws the ordinary histogram bars first. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.