Reputation:
How to create a histogram on python using my own frequencies, when i use bins it gives me another values: i have 1000 numbers between 0 and 1, frquencies are for example i have 63 number between [0, 0.05[ but in the histogram i want that the frequencie will be 0.063 all frenquencies are divised by 1000
Frequencies =[0.063,0.047,0.049,0.051,0.049,0.045,0.033,0.055,0.047,0.052,0.048,0.067,0.033,0.056,0.055,0.041,0.048,0.05,0.072,0.039]
Intervals = [0 , 0.05 , 0.1 , 0.15 , 0.2 , 0.25 , 0.3 , 0.35 , 0.4 , 0.45 , 0.5 , 0.55 , 0.6 , 0.65 , 0.7, 0.75 ,0.8 , 0.85, 0.9 , 0.95, 1]
i need to plot a histogram that for example for the interval [0, 0.05[ the height will be 0.063 i tried this
plt.hist(Frequencies , bins = Intervals)
but the reslut is wrong
Upvotes: 0
Views: 164
Reputation: 30579
You already have the frequencies, so you don't need plt.hist
but simply plt.bar
:
x = range(len(Frequencies))
plt.bar(x, Frequencies)
tick_labels = [f'[{Intervals[i]},{Intervals[i+1]}[' for i in range(len(Intervals)-1)]
plt.xticks(x, tick_labels, rotation='vertical')
Upvotes: 2