using StatsBase, KernelDensity, Colors, LinearAlgebra
using Random
using CairoMakie, ColorSchemes
include("makieTheme6.jl")
Random.seed!(13)
b = randn(1000)
fig = Figure(resolution = (600, 400), font = "sans")
ax4 = Axis(fig, xlabel = "value", ylabel = "" )
h = fit(Histogram, b, nbins = 50)
h = normalize(h)
#histogram
plot!(ax4, h, color = (:dodgerblue, 0.25), strokecolor = :black, strokewidth = 0.5)
# density distribution
d = kde(b)
linec = lines!(d.x, d.density, color = :orangered, linewidth = 1.5)
bandc = band!(d.x, 0*d.density, d.density, color = (:yellow, 0.25))
leg = Legend(fig, [[linec, bandc]], ["density"], framevisible = true,
tellheight = false, tellwidth = false, halign = :right, valign = :top)
fig[1,1] = ax4
fig[1,1] = leg
#save("./results/FigHistogramDensity.png", fig, px_per_unit = 2)
fig