Seaborn distplot has a flag norm_hist
. When switched on, the distplot is normalized so that it integrates to 1.
Here is a small example:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
a = np.random.randn(10000)
a = a[(-2<a) * (a<2)]
sns.distplot(a=a, bins=np.linspace(-2, 2, 6), norm_hist=True, kde=False)
plt.show()
This creates the following plot:
It looks a bit like a triangle and you can see that it integrates to 1. A triangle of width 4 and height 0.5 has the area 1.
Is it possible to normalize this while ignoring the width of each bin? So that the bars add up to 1 (it would have this behaviour if all bins together spanned a width of 1).
In my scenario, users are binned based on a continuous feature. In the distplot, I would like to show what percentage of users falls into each bin. But when the feature is rescaled, the heights of the corresponding bars change.