{"spec_id":"histogram-overlapping","library":"makie","language":"julia","code":"# anyplot.ai\n# histogram-overlapping: Overlapping Histograms\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 90/100 | Created: 2026-08-18\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 IMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — brand green, ALWAYS first series\n    colorant\"#C475FD\",  # 2 — lavender\n    colorant\"#4467A3\",  # 3 — blue\n]\n\n# --- Data ---------------------------------------------------------------\n# Reaction times (ms) across three UI response conditions\nn_per_group = 220\ncondition_a = 240 .+ 35 .* randn(n_per_group)          # baseline\ncondition_b = 265 .+ 42 .* randn(n_per_group)           # added latency\ncondition_c = 225 .+ 30 .* randn(n_per_group)           # optimized\n\nbin_edges = range(minimum(vcat(condition_a, condition_b, condition_c)) - 5,\n                   maximum(vcat(condition_a, condition_b, condition_c)) + 5;\n                   length = 31)\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-overlapping · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Response Time (ms)\",\n    ylabel             = \"Number of Trials\",\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    xgridvisible       = false,\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.15),\n)\n\nhist!(ax, condition_a; bins = bin_edges, color = (IMPRINT_PALETTE[1], 0.42),\n      strokewidth = 1.5, strokecolor = IMPRINT_PALETTE[1], label = \"Baseline\")\nhist!(ax, condition_b; bins = bin_edges, color = (IMPRINT_PALETTE[2], 0.42),\n      strokewidth = 1.5, strokecolor = IMPRINT_PALETTE[2], label = \"Added Latency\")\nhist!(ax, condition_c; bins = bin_edges, color = (IMPRINT_PALETTE[3], 0.42),\n      strokewidth = 2.5, strokecolor = IMPRINT_PALETTE[3], label = \"Optimized\")\n\n# Distinctive Makie touch: a linked secondary y-axis overlays smoothed KDE\n# outlines so each group's shape stays traceable through the dense triple-overlap.\nax2 = Axis(\n    fig[1, 1];\n    yaxisposition      = :right,\n    backgroundcolor    = :transparent,\n    ylabel             = \"Density\",\n    ylabelsize         = 14,\n    ylabelcolor        = INK_SOFT,\n    yticklabelsize     = 12,\n    yticklabelcolor    = INK_SOFT,\n    ytickcolor         = INK_SOFT,\n    leftspinevisible   = false,\n    rightspinecolor    = INK_SOFT,\n    topspinevisible    = false,\n    bottomspinevisible = false,\n    xgridvisible       = false,\n    ygridvisible       = false,\n)\nhidexdecorations!(ax2)\nlinkxaxes!(ax, ax2)\n\ndensity!(ax2, condition_a; color = :transparent, strokecolor = IMPRINT_PALETTE[1], strokewidth = 2)\ndensity!(ax2, condition_b; color = :transparent, strokecolor = IMPRINT_PALETTE[2], strokewidth = 2)\ndensity!(ax2, condition_c; color = :transparent, strokecolor = IMPRINT_PALETTE[3], strokewidth = 3)\n\ntext!(\n    ax, 0.02, 0.96;\n    text     = \"Optimized: fastest & most consistent response times\",\n    space    = :relative,\n    align    = (:left, :top),\n    fontsize = 12,\n    color    = IMPRINT_PALETTE[3],\n)\n\naxislegend(ax; position = :rt, labelsize = 12, labelcolor = INK_SOFT,\n           framevisible = false, backgroundcolor = :transparent)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}