Density and histograms

I am using Julia for plotting the density of a data using density(). I wanted to know if there is any way to obtain the data points of the density(), like the values that is plotted by density(). I can obtain the histogram heights but they vary from the density plot.
Also, is there any easy way to find the density values of a given dataset?

Either normalize yourself

julia> using StatsBase
julia> h = fit(Histogram, rand(1000), 0:0.01:1);
julia> h.weights ./ sum(h.weights)
100-element Vector{Float64}:
 0.012
 0.01
 0.013
...

or use LinearAlgebra.normalize

julia> using LinearAlgebra
julia> normalize(h)
Histogram{Float64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
  0.0:0.01:1.0
weights: [1.2, 1.0, 1.3, 0.9, 1.6, 0.7, 0.9, 1.0, 1.3, 0.7  …  1.2, 1.0, 0.8, 0.9, 0.9, 1.0, 1.3, 0.8, 0.8, 1.5]
closed: left
isdensity: true

Actually I was asking to find the density plot values.
photo_2024-06-09_21-14-16

Like in the image, the histogram plot has different heights on both side, but the density plot is almost symmetric. I wanted to obtain the values of the density distribution.

How did you get the density? What package are you using?

There’s a simple density function in this package: GitHub - m3g/EasyFit.jl: Easy interface for obtaining fits for 2D data

It is possible that the density is actually symmetric and that the difference between the peaks is simply an artifact owing to how the histogram is binned. The left hand side starts at -3000, while the right hand side ends at 3000+one bin width, and if the last and next-to-last bins are added together they would probably add up to close to the height of the opposite side.

If you look at the data itself, is it symmetric? It may be worthwhile to play around with different binning options (left/right/center justified, smaller bin sizes, etc) to see what effect that has. Or try a cumulative histogram since they do not have bin size artifacts.