Reputation: 379
I have the following histogram:
The blue columns are the data while the red line is the theoretical line. I generated this by first plotting the histogram, and then scaling the theoretical curve (which has a maximum of 1) to the approximate value of the peak of the histogram. I want to avoid this manual scaling by making the histogram have a peak value of 1 as well. How do I do this with Python?
A previous question provides a way to get the peak value (122 in my case) but I can't figure out how to use that to scale the histogram. It seems like once I invoke the hist command it will create the current histogram, which makes sense since that's what histograms are - the columns shouldn't take fractional values. In other words I need a different approach. Any help appreciated.
Upvotes: 1
Views: 1951
Reputation: 509
Call plt.hist
again but with weights
parameter that specifies scaling factors:
plt.hist(hdata, bins=40, weights=[1/y.max()]*x_len)
Upvotes: 4