I would appreciate any insight with the following.
I want to plot two datasets on one common histogram such that both histograms do not have their tops cut-off and have probability distributions ranging from 0 to 1.
Let me explain what I mean. So far, I can plot the two datasets on one histogram nicely and force the integral of both distributions to be 1 by writing normed = 1
in ax.hist()
, as seen in the following figure:
and which is produced from code like this:
x1, w1, patches1 = ax.hist(thing1, bins=300, edgecolor='b', color='b', histtype='stepfilled', alpha=0.2, normed = 1)
x2, w2, patches2 = ax.hist(thing2, bins=300, edgecolor='g', color='g', histtype='stepfilled', alpha=0.2, normed = 1)
In the general case, one probability distribution is much higher than the other and it makes it hard to read the plot clearly.
So, I've tried to normalise both such that they would both range from 0 to 1 on the y axis and still preserve their shape. For example, I've tried the following code:
for item in patches1:
item.set_height(item.get_height()/sum(x1))
which is taken from the discussion here How to normalize a histogram in python?, but python throws me an error message saying there is no such quality as get_height
.
My question is simply: How can I have it that so that the y axis ranges from 0 to 1 and preserve the shape of both distributions?