x = np.random.rand(1000)
mass = np.random.rand(1000)
npoints = 200
ksort = np.argsort(x)
bins = x[ksort[0::npoints]]
bins = np.append(bins, x[ksort[-1]])
fig = plt.figure(1, figsize=(10, 5))
ax1 = fig.add_subplot(121)
ax2 = fig.add_subplot(122)
yhist, xhist = np.histogram(x, bins, weights=None)
ax1.plot(0.5 * (xhist[1:] + xhist[:-1]), yhist, linestyle='steps-mid', lw=2,
    color='k')
yhist, xhist = np.histogram(x, bins, weights=mass)
ax2.plot(0.5 * (xhist[1:] + xhist[:-1]), yhist, linestyle='steps-mid', lw=2,
    color='k')
ax1.set_xlabel('x', size=15)
ax1.set_ylabel('Number of points per bin', size=15)
ax2.set_xlabel('x', size=15)
ax2.set_ylabel('Mass per bin', size=15)
Histogram with equal number of points in each bin