{"spec_id":"density-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# density-basic: Basic Density Plot\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 85/100 | Created: 2026-05-30\n\nusing CairoMakie\nusing Colors\nusing Random\nusing Statistics\n\nRandom.seed!(42)\n\n# Theme tokens — Imprint palette\nconst THEME       = get(ENV, \"ANYPLOT_THEME\", \"light\")\nconst PAGE_BG     = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nconst ELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nconst INK         = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT    = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — brand green (always first)\n    colorant\"#C475FD\",  # 2 — lavender\n    colorant\"#4467A3\",  # 3 — blue\n    colorant\"#BD8233\",  # 4 — ochre\n    colorant\"#AE3030\",  # 5 — matte red\n    colorant\"#2ABCCD\",  # 6 — cyan\n    colorant\"#954477\",  # 7 — rose\n    colorant\"#99B314\",  # 8 — lime\n]\n\n# Data — daily commute durations (minutes) for two transport modes\nn_bike = 280\nn_bus  = 320\n\nbike_times = clamp.(randn(n_bike) .* 5.0  .+ 22.0,  8.0, 50.0)\nbus_times  = clamp.(randn(n_bus)  .* 11.0 .+ 38.0, 10.0, 85.0)\n\nmean_bike = mean(bike_times)\nmean_bus  = mean(bus_times)\nmean_diff = round(Int, mean_bus - mean_bike)\n\n# Theme-adaptive fill alpha: dark background absorbs low-alpha fills — boost for visibility\nbike_alpha = THEME == \"dark\" ? 0.42 : 0.30\nbus_alpha  = THEME == \"dark\" ? 0.48 : 0.30\n\n# Plot\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nLabel(fig[0, 1],\n    \"Bus commutes average ~$(mean_diff) min longer — bicycle wins for most urban trips\";\n    color     = INK_SOFT,\n    fontsize  = 11,\n    halign    = :left,\n    tellwidth = false,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"density-basic · julia · makie · anyplot.ai\",\n    titlesize          = 22,\n    titlecolor         = INK,\n    xlabel             = \"Commute 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    xgridvisible       = false,\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.12),\n    yminorgridvisible  = false,\n    xminorgridvisible  = false,\n)\n\n# Density curves with theme-adaptive fills\ndensity!(ax, bike_times;\n    color       = (IMPRINT_PALETTE[1], bike_alpha),\n    strokecolor = IMPRINT_PALETTE[1],\n    strokewidth = 2.5,\n    label       = \"Bicycle\",\n)\n\ndensity!(ax, bus_times;\n    color       = (IMPRINT_PALETTE[3], bus_alpha),\n    strokecolor = IMPRINT_PALETTE[3],\n    strokewidth = 2.5,\n    label       = \"Bus\",\n)\n\n# Mean reference lines — dashed verticals highlight the distributional gap\nvlines!(ax, mean_bike;\n    color     = (IMPRINT_PALETTE[1], 0.65),\n    linestyle = :dash,\n    linewidth = 1.5,\n)\nvlines!(ax, mean_bus;\n    color     = (IMPRINT_PALETTE[3], 0.65),\n    linestyle = :dash,\n    linewidth = 1.5,\n)\n\n# Rug plot — individual observations as tick marks along x-axis baseline\nscatter!(ax, bike_times, zeros(n_bike);\n    marker      = :vline,\n    markersize  = 10,\n    color       = (IMPRINT_PALETTE[1], 0.30),\n    strokewidth = 0,\n)\nscatter!(ax, bus_times, zeros(n_bus);\n    marker      = :vline,\n    markersize  = 10,\n    color       = (IMPRINT_PALETTE[3], 0.30),\n    strokewidth = 0,\n)\n\naxislegend(ax;\n    backgroundcolor = ELEVATED_BG,\n    labelcolor      = INK_SOFT,\n    framecolor      = INK_SOFT,\n    framevisible    = true,\n    position        = :rt,\n    labelsize       = 12,\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}