{"spec_id":"histogram-kde","library":"makie","language":"julia","code":"# anyplot.ai\n# histogram-kde: Histogram with KDE Overlay\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 89/100 | Created: 2026-08-05\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# --- Theme tokens -----------------------------------------------------------\nconst THEME    = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG  = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst INK      = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\n\n# Imprint categorical palette — 8 hues, theme-independent, hybrid-v3 sort\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\", colorant\"#C475FD\", colorant\"#4467A3\", colorant\"#BD8233\",\n    colorant\"#AE3030\", colorant\"#2ABCCD\", colorant\"#954477\", colorant\"#99B314\",\n]\n\n# --- Data ---------------------------------------------------------------\n# Customer session duration on a marketing site — right-skewed: most visits\n# are brief, a long tail of engaged sessions stretches the distribution.\nn = 600\nsession_minutes = exp.(1.1 .+ 0.55 .* randn(n))\n\n# --- Plot -----------------------------------------------------------------\nfig = Figure(\n    resolution      = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"histogram-kde · julia · makie · anyplot.ai\",\n    titlesize          = 25,\n    titlecolor         = INK,\n    xlabel             = \"Session Duration (minutes)\",\n    ylabel             = \"Density\",\n    xlabelsize         = 14,\n    ylabelsize         = 14,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 12,\n    yticklabelsize     = 12,\n    xticklabelcolor    = INK_SOFT,\n    yticklabelcolor    = INK_SOFT,\n    xtickcolor         = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    backgroundcolor    = PAGE_BG,\n    topspinevisible    = false,\n    rightspinevisible  = false,\n    leftspinecolor     = INK_SOFT,\n    bottomspinecolor   = INK_SOFT,\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    xgridvisible       = false,\n)\n\nhist!(\n    ax, session_minutes;\n    bins = 30,\n    normalization = :pdf,\n    color = (IMPRINT_PALETTE[1], 0.5),\n    strokewidth = 0,\n    label = \"Observed sessions\",\n)\n\ndensity!(\n    ax, session_minutes;\n    color = :transparent,\n    strokecolor = IMPRINT_PALETTE[2],\n    strokewidth = 3.5,\n    label = \"KDE\",\n)\n\naxislegend(\n    ax;\n    position = :rt,\n    labelcolor = INK,\n    backgroundcolor = ELEVATED_BG,\n    framevisible = false,\n)\n\n# --- Annotation: call out the peak session length ---------------------------\ntext!(\n    ax, 4.6, 0.275;\n    text = \"Peak ~2 min\\nsessions\",\n    color = INK_SOFT,\n    fontsize = 13,\n    align = (:left, :center),\n)\nlines!(\n    ax, [4.4, 2.3], [0.272, 0.283];\n    color = INK_SOFT,\n    linewidth = 1.2,\n)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}