{"spec_id":"polar-scatter","library":"makie","language":"julia","code":"# anyplot.ai\n# polar-scatter: Polar Scatter Plot\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 80/100 | Created: 2026-09-05\n\nusing CairoMakie\nusing Colors\nusing Random\n\nRandom.seed!(42)\n\n# Theme tokens (see prompts/default-style-guide.md \"Background\" + \"Theme-adaptive Chrome\")\nTHEME = get(ENV, \"ANYPLOT_THEME\", \"light\")\nPAGE_BG = THEME == \"light\" ? colorant\"#FAF8F1\" : colorant\"#1A1A17\"\nELEVATED_BG = THEME == \"light\" ? colorant\"#FFFDF6\" : colorant\"#242420\"\nINK = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nINK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\nGRID = THEME == \"light\" ? RGBAf(0.102, 0.102, 0.090, 0.15) : RGBAf(0.941, 0.937, 0.910, 0.15)\n\n# Imprint palette (see prompts/default-style-guide.md \"Categorical Palette\") — first 4 positions\nIMPRINT_PALETTE = [\n    colorant\"#009E73\",  # 1 — brand green — ALWAYS first series\n    colorant\"#C475FD\",  # 2 — lavender\n    colorant\"#4467A3\",  # 3 — blue\n    colorant\"#BD8233\",  # 4 — ochre\n]\n\n# Data — wind observations: bearing (compass direction the wind blows FROM) and speed,\n# clustered around a south-southwesterly prevailing direction, split by time of day.\n# 205° is deliberately offset from the 45°-spaced compass ticks (S=180°, SW=225°) so\n# the prevailing-direction indicator below never sits directly on top of a gridline spoke.\ntime_of_day = [\"Morning\", \"Afternoon\", \"Evening\", \"Night\"]\nn_per_period = 30\nprevailing_bearing = 205.0\n\nwind_bearing_deg = Float64[]\nwind_speed = Float64[]\nperiod_index = Int[]\nfor (i, period) in enumerate(time_of_day)\n    spread = 35.0 + 10.0 * i\n    bearings = mod.(prevailing_bearing .+ spread .* randn(n_per_period), 360.0)\n    speeds = abs.(4.0 .+ 1.6 .* randn(n_per_period)) .+ 1.0 * i\n    append!(wind_bearing_deg, bearings)\n    append!(wind_speed, speeds)\n    append!(period_index, fill(i, n_per_period))\nend\nwind_bearing_rad = deg2rad.(wind_bearing_deg)\n\n# Plot\nfig = Figure(size = (1600, 900), fontsize = 14, backgroundcolor = PAGE_BG)\n\nax = PolarAxis(\n    fig[1, 1];\n    title = \"polar-scatter · julia · makie · anyplot.ai\",\n    titlesize = 20,\n    titlecolor = INK,\n    theta_0 = -pi / 2,\n    direction = -1,\n    thetaticks = ((0:45:315) .* pi / 180, [\"N\", \"NE\", \"E\", \"SE\", \"S\", \"SW\", \"W\", \"NW\"]),\n    thetaticklabelsize = 12,\n    thetaticklabelcolor = INK_SOFT,\n    rticks = 0:4:12,\n    rlimits = (0.0, 14.0),  # tight to the actual data extent (max ≈ 12.4 m/s), no dead outer ring\n    rticklabelsize = 12,\n    rticklabelcolor = INK_SOFT,\n    rtickformat = values -> [\"$(round(Int, v)) m/s\" for v in values],\n    rtickangle = pi / 4,  # place radial tick labels near NE, clear of the SW data cluster\n    spinecolor = INK_SOFT,\n    rgridcolor = GRID,\n    thetagridcolor = GRID,\n    backgroundcolor = PAGE_BG,\n)\n\nseries_plots = []\nfor (i, period) in enumerate(time_of_day)\n    mask = period_index .== i\n    p = scatter!(\n        ax, wind_bearing_rad[mask], wind_speed[mask];\n        color = IMPRINT_PALETTE[i], markersize = 9, alpha = 0.6,\n        strokewidth = 1, strokecolor = PAGE_BG, label = period,\n    )\n    push!(series_plots, p)\nend\n\n# Prevailing-direction focal point: circular mean bearing across all observations,\n# drawn on top of the data as a bold dashed spoke reaching just short of the axis\n# edge, clear of every 45°-spaced compass gridline (see prevailing_bearing note above)\nmean_bearing_rad = atan(sum(sin, wind_bearing_rad), sum(cos, wind_bearing_rad))\nlines!(\n    ax, fill(mean_bearing_rad, 2), [0.0, 12.2];\n    color = INK, linestyle = :dash, linewidth = 2.5,\n)\ntext!(\n    ax, mean_bearing_rad, 13.0;\n    text = \"prevailing\", color = INK, fontsize = 13, font = :bold,\n    align = (:center, :center),\n)\n\nLegend(\n    fig[1, 2], series_plots, time_of_day;\n    labelcolor = INK_SOFT, labelsize = 12,\n    backgroundcolor = ELEVATED_BG, framevisible = false,\n)\ncolsize!(fig.layout, 1, Relative(0.85))\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}