{"spec_id":"violin-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# violin-basic: Basic Violin Plot\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 87/100 | Created: 2026-05-29\n\nusing CairoMakie\nusing Colors\nusing Random\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\"\nconst INK_MUTED   = THEME == \"light\" ? colorant\"#6B6A63\" : colorant\"#A8A79F\"\n\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — brand green\n    colorant\"#C475FD\",  # 2 — lavender\n    colorant\"#4467A3\",  # 3 — blue\n    colorant\"#BD8233\",  # 4 — ochre\n]\n\n# Data — test scores (50–100) across 4 class groups with distinct distribution shapes\nn = 200\n\nscores_a = clamp.(randn(n) .* 8.0 .+ 74.0, 50.0, 100.0)          # roughly normal\nscores_b = clamp.(vcat(randn(n ÷ 2) .* 5.0 .+ 63.0,\n                       randn(n ÷ 2) .* 5.0 .+ 87.0), 50.0, 100.0) # bimodal\nscores_c = clamp.(50.0 .+ 50.0 .* rand(n) .^ 2, 50.0, 100.0)     # right-skewed\nscores_d = clamp.(randn(n) .* 3.5 .+ 91.0, 50.0, 100.0)           # narrow, high-performing\n\ngroups = vcat(fill(1, n), fill(2, n), fill(3, n), fill(4, n))\nvalues = vcat(scores_a, scores_b, scores_c, scores_d)\n\ngroup_labels = [\"Group A\", \"Group B\", \"Group C\", \"Group D\"]\ndist_labels  = [\"normal\", \"bimodal ★\", \"right-skewed\", \"narrow\"]\n\n# Plot\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             = \"Class Group\",\n    ylabel             = \"Test Score\",\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    yminorgridvisible  = false,\n    xminorgridvisible  = false,\n    xticks             = (1:4, group_labels),\n)\n\n# Draw one violin per group with Imprint palette color\nfor (i, col) in enumerate(IMPRINT_PALETTE)\n    mask = groups .== i\n    violin!(ax, groups[mask], values[mask];\n        color       = (col, 0.75),\n        strokewidth = 1.0,\n        strokecolor = INK_SOFT,\n    )\nend\n\n# Overlay narrow boxplot to show quartiles and median\nboxplot!(ax, groups, values;\n    color        = (:white, 0.0),\n    strokecolor  = INK,\n    strokewidth  = 1.5,\n    mediancolor  = INK,\n    width        = 0.12,\n    whiskerwidth = 0.5,\n    show_outliers = false,\n)\n\n# Callout annotation — draw viewer's eye to the bimodal shape in Group B\ntext!(ax, 2.0, 96.5;\n    text     = \"bimodal\",\n    color    = IMPRINT_PALETTE[2],\n    fontsize = 12,\n    font     = :bold,\n    align    = (:center, :bottom),\n)\n\n# Custom Legend with per-group color swatches and distribution type labels\nlegend_elements = [PolyElement(color = (IMPRINT_PALETTE[i], 0.75),\n                               strokecolor = INK_SOFT, strokewidth = 1.0)\n                   for i in eachindex(group_labels)]\nlegend_labels   = [\"$(group_labels[i]): $(dist_labels[i])\" for i in eachindex(group_labels)]\nLegend(fig[1, 2], legend_elements, legend_labels, \"Distribution Shape\";\n    framevisible    = false,\n    backgroundcolor = PAGE_BG,\n    labelcolor      = INK_SOFT,\n    titlecolor   = INK,\n    titlesize    = 13,\n    labelsize    = 12,\n    padding      = (6, 6, 6, 6),\n)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}