The one-dimensional density is defined as the values / length
. But it's also a normalization method for histograms.
So in order to get from your original values to the density
-values just divide by the total count (normalization) and the bin-width (density):
bin_width = bins[1:] - bins[:-1]
values2 = values1 / np.sum(values1) / bin_width
A quick test with a random array:
from matplotlib import pylab
import numpy as np
data = np.random.randint(0,10, 1000)
bins = np.array([0,1,2,5,11])
values1, _ = pylab.histogram(data, bins, density = False)
print(values1)
# [ 97, 117, 278, 508]
values2, _ = pylab.histogram(data, bins, density = True)
print(values2)
# [ 0.097, 0.117, 0.09266667, 0.08466667]
bin_width = bins[1:] - bins[:-1]
print(values1 / np.sum(values1) / bin_width)
# [ 0.097, 0.117, 0.09266667, 0.08466667]
So it is the same for this case.