{"spec_id":"violin-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# violin-basic: Basic Violin Plot\n# Library: makie 0.24.16 | Julia 1.13.4\n# Quality: 83/100 | Updated: 2026-11-27\n\nusing CairoMakie\nusing Colors\nusing DataFrames\nusing Random\n\n# Theme tokens — Imprint palette\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\"\n\n# Imprint palette\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",\n    colorant\"#C475FD\",\n    colorant\"#4467A3\",\n    colorant\"#BD8233\",\n    colorant\"#AE3030\",\n    colorant\"#2ABCCD\",\n    colorant\"#954477\",\n    colorant\"#99B314\",\n]\n\n# Columns: set these to your table's column names\nconst MODE     = \"Transport mode\"          # role: category\nconst DURATION = \"Commute duration (min)\"  # role: value\n\n# Data: replace this block with your own table, for example df = CSV.read(\"commutes.csv\", DataFrame)\nRandom.seed!(42)\nn = 250\nmodes = [\"Walk\", \"Bike\", \"Bus\", \"Car\"]\ndurations = [\n    clamp.(randn(n) .* 4.0 .+ 18.0, 4.0, Inf),                                  # walk: narrow\n    clamp.(randn(n) .* 7.0 .+ 24.0, 4.0, Inf),                                  # bike: roughly normal\n    clamp.(10.0 .+ 55.0 .* rand(n) .^ 2.5, 4.0, Inf),                           # bus: right-skewed\n    clamp.(vcat(randn(n ÷ 2) .* 4.0 .+ 16.0, randn(n ÷ 2) .* 8.0 .+ 48.0), 4.0, Inf), # car: bimodal\n]\ndf = DataFrame(\n    MODE => repeat(modes; inner = n),\n    DURATION => vcat(durations...),\n)\n\n# Plot: reads only df and the constants above\ncategories = unique(df[!, MODE])\nx = [findfirst(==(m), categories) for m in df[!, MODE]]\nvalues = df[!, DURATION]\n\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"violin-basic · julia · makie · anyplot.ai\",\n    titlesize          = 22,\n    titlecolor         = INK,\n    xlabel             = MODE,\n    ylabel             = DURATION,\n    xlabelsize         = 18,\n    ylabelsize         = 18,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 16,\n    yticklabelsize     = 16,\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    yminorgridvisible  = false,\n    xminorgridvisible  = false,\n    xticks             = (eachindex(categories), categories),\n)\n\n# One violin per category, one Imprint color each; tails end at the data range\nviolin!(ax, x, values;\n    color       = [RGBAf(c, 0.75) for c in IMPRINT_PALETTE[x]],\n    datalimits  = extrema,\n    strokewidth = 1.0,\n    strokecolor = INK_SOFT,\n)\n\n# Quartile box and median line inside each violin\nboxplot!(ax, x, values;\n    color         = (:white, 0.0),\n    strokecolor   = INK,\n    strokewidth   = 1.5,\n    mediancolor   = INK,\n    whiskercolor  = INK,\n    width         = 0.12,\n    whiskerwidth  = 0.5,\n    show_outliers = false,\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}