I am stuck when working with plt.hist(density=True) although I have set weights. My goal is to retrieve a histogram in which the sum of bars (y-axes) equals 1. It is a deeply discussed issue, however [1][2] I can´t derive the right solution. Here is my code:
data = np.array(data).astype("float32")
weights = np.ones_like(data)/float(len(data))
n, bins, patches = plt.hist(x=data, density=True, bins=20, color='#0504aa',weights=weights,
alpha=0.7, rwidth=0.85)
which creates:
The bars are obviously not summing up to one. Does anybody have a solution for my issue. Maybe it is already posted somewhere, but I am not able to find it?
Greetings