{"spec_id":"polar-line","library":"makie","language":"julia","code":"# anyplot.ai\n# polar-line: Polar Line Plot\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 89/100 | Created: 2026-09-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 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 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# Average monthly rainfall (mm) across three climate zones — a seasonal cycle\nmonth_labels = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"]\nmonths = 0:11\n\ntropical = 180 .+ 60 .* sin.(2pi .* (months .- 3) ./ 12) .+ 8 .* randn(12)\ntemperate = 90 .+ 40 .* sin.(2pi .* (months .- 9) ./ 12) .+ 6 .* randn(12)\narid = 25 .+ 15 .* sin.(2pi .* months ./ 12) .+ 3 .* randn(12)\n\ntropical = max.(tropical, 5.0)\ntemperate = max.(temperate, 5.0)\narid = max.(arid, 2.0)\n\ntheta = collect(months) ./ 12 .* 2pi\ntheta_closed = vcat(theta, 2pi)  # wrap December back to January to close each loop\n\ntropical_closed = vcat(tropical, tropical[1])\ntemperate_closed = vcat(temperate, temperate[1])\narid_closed = vcat(arid, arid[1])\n\npeak_idx = argmax(tropical)  # Tropical is the highest-variance series — the story to tell\npeak_theta = theta[peak_idx]\npeak_r = tropical[peak_idx]\n\n# --- Plot -------------------------------------------------------------------\nfig = Figure(size = (1200, 1200), backgroundcolor = PAGE_BG)\n\nax = PolarAxis(\n    fig[1, 1];\n    theta_0 = pi / 2,                  # January at the top\n    direction = 1,                     # months advance counter-clockwise\n    title = \"polar-line · julia · makie · anyplot.ai\",\n    titlesize = 20,\n    titlecolor = INK,\n    backgroundcolor = PAGE_BG,\n    thetaticks = (0:(pi / 6):(11pi / 6), month_labels),\n    thetaticklabelsize = 14,\n    thetaticklabelcolor = INK_SOFT,\n    rticks = 0:50:250,\n    rtickformat = values -> [\"$(round(Int, v)) mm\" for v in values],\n    rtickangle = pi / 12,               # offset from the January spoke to avoid label clash\n    rticklabelsize = 12,\n    rticklabelcolor = INK_SOFT,\n    spinecolor = INK_SOFT,\n    rgridcolor = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    thetagridcolor = RGBAf(INK.r, INK.g, INK.b, 0.15),\n)\n\n# Fill under the highest-variance series gives the chart a focal point\nband!(ax, theta_closed, zeros(length(theta_closed)), tropical_closed;\n    color = (IMPRINT_PALETTE[1], 0.20))\n\nlines!(ax, theta_closed, tropical_closed; color = IMPRINT_PALETTE[1], linewidth = 3.5)\nlines!(ax, theta_closed, temperate_closed; color = IMPRINT_PALETTE[2], linewidth = 3.5)\nlines!(ax, theta_closed, arid_closed; color = IMPRINT_PALETTE[3], linewidth = 3.5)\n\n# Markers at each of the 12 monthly measurements, not just the interpolated line\nscatter!(ax, theta, tropical; color = IMPRINT_PALETTE[1], markersize = 9, strokewidth = 0)\nscatter!(ax, theta, temperate; color = IMPRINT_PALETTE[2], markersize = 9, strokewidth = 0)\nscatter!(ax, theta, arid; color = IMPRINT_PALETTE[3], markersize = 9, strokewidth = 0)\n\n# Callout on Tropical's wet-season peak — the clearest story in the data\ntext!(\n    ax, peak_theta, peak_r;\n    text = \"peak wet season\",\n    color = INK,\n    fontsize = 16,\n    font = :bold,\n    align = (:center, :bottom),\n    offset = (0, 14),\n)\n\n# A slim row below the plot (not a side column) keeps the circle horizontally\n# centered in the square canvas\nLegend(\n    fig[2, 1],\n    [LineElement(color = IMPRINT_PALETTE[1], linewidth = 3.5),\n     LineElement(color = IMPRINT_PALETTE[2], linewidth = 3.5),\n     LineElement(color = IMPRINT_PALETTE[3], linewidth = 3.5)],\n    [\"Tropical\", \"Temperate\", \"Arid\"];\n    orientation = :horizontal,\n    tellwidth = false,\n    labelsize = 16,\n    labelcolor = INK,\n    backgroundcolor = ELEVATED_BG,\n    framevisible = false,\n)\ncolsize!(fig.layout, 1, Fixed(1200))\nrowsize!(fig.layout, 2, Fixed(70))\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}