{"spec_id":"scatter-complex-plane","library":"makie","language":"julia","code":"# anyplot.ai\n# scatter-complex-plane: Complex Plane Visualization (Argand Diagram)\n# Library: makie 0.22.10 | Julia 1.11.9\n# Quality: 88/100 | Created: 2026-06-02\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\",  # 1 — brand green (first series)\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 — 5th roots of unity: e^(2πik/5) for k = 0,...,4\nn_roots = 5\ntheta_roots = [2π * k / n_roots for k in 0:(n_roots - 1)]\nre_roots = cos.(theta_roots)\nim_roots = sin.(theta_roots)\nroot_labels = [\"z₀\", \"z₁\", \"z₂\", \"z₃\", \"z₄\"]\n\n# Arbitrary complex numbers outside the unit circle\nre_arb = [1.5, -1.3, 0.6]\nim_arb = [1.1, 0.8, -1.7]\narb_labels = [\"w₁\", \"w₂\", \"w₃\"]\n\n# Unit circle reference (parametric)\ntheta_circle = LinRange(0, 2π, 300)\n\n# Figure — square canvas: size=(1200,1200) × px_per_unit=2 → 2400×2400 px\nfig = Figure(\n    size            = (1200, 1200),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"scatter-complex-plane · julia · makie · anyplot.ai\",\n    titlesize          = 20,\n    titlecolor         = INK,\n    xlabel             = \"Re(z)\",\n    ylabel             = \"Im(z)\",\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    xgridcolor         = (INK_SOFT, 0.12),\n    ygridcolor         = (INK_SOFT, 0.12),\n    aspect             = DataAspect(),\n)\n\n# Unit circle — dashed reference\nlines!(ax, cos.(theta_circle), sin.(theta_circle);\n    linestyle = :dash,\n    color     = (INK_SOFT, 0.8),\n    linewidth = 1.5,\n)\n\n# Real and imaginary axis lines through origin\nhlines!(ax, [0.0]; color = (INK_SOFT, 0.5), linewidth = 0.8)\nvlines!(ax, [0.0]; color = (INK_SOFT, 0.5), linewidth = 0.8)\n\n# Arrows from origin to 5th roots of unity\nroots_origins = fill(Point2f(0, 0), n_roots)\nroots_dirs    = Point2f.(re_roots, im_roots)\narrows!(ax, roots_origins, roots_dirs;\n    color     = IMPRINT_PALETTE[1],\n    linewidth = 2.0,\n    arrowsize = 16,\n)\n\n# Arrows from origin to arbitrary complex numbers\narb_origins = fill(Point2f(0, 0), length(re_arb))\narb_dirs    = Point2f.(re_arb, im_arb)\narrows!(ax, arb_origins, arb_dirs;\n    color     = IMPRINT_PALETTE[2],\n    linewidth = 2.0,\n    arrowsize = 16,\n)\n\n# Scatter points — 5th roots of unity (circle markers)\nscatter!(ax, re_roots, im_roots;\n    color       = IMPRINT_PALETTE[1],\n    markersize  = 14,\n    marker      = :circle,\n    strokewidth = 1.5,\n    strokecolor = PAGE_BG,\n    label       = \"5th roots of unity\",\n)\n\n# Scatter points — arbitrary complex numbers (diamond markers for shape encoding)\nscatter!(ax, re_arb, im_arb;\n    color       = IMPRINT_PALETTE[2],\n    markersize  = 14,\n    marker      = :diamond,\n    strokewidth = 1.5,\n    strokecolor = PAGE_BG,\n    label       = \"Arbitrary complex\",\n)\n\n# Labels for roots of unity — symbolic name + rectangular form annotation\nlabel_offset = 0.18\nfor (r_val, i_val, lbl) in zip(re_roots, im_roots, root_labels)\n    mag = sqrt(r_val^2 + i_val^2)\n    ox  = r_val / mag * label_offset\n    oy  = i_val / mag * label_offset\n    h   = r_val > 0.1 ? :left : (r_val < -0.1 ? :right : :center)\n    v   = i_val > 0.1 ? :bottom : (i_val < -0.1 ? :top : :center)\n    # Symbolic label\n    text!(ax, [Point2f(r_val + ox, i_val + oy)];\n        text     = [lbl],\n        fontsize = 14,\n        color    = INK,\n        align    = [(h, v)],\n    )\n    # Rectangular form — placed further out along the same radial direction\n    rect_str = i_val >= 0 ?\n        \"$(round(r_val, digits=2))+$(round(i_val, digits=2))i\" :\n        \"$(round(r_val, digits=2))$(round(i_val, digits=2))i\"\n    rox = r_val / mag * (label_offset + 0.24)\n    roy = i_val / mag * (label_offset + 0.24)\n    text!(ax, [Point2f(r_val + rox, i_val + roy)];\n        text     = [rect_str],\n        fontsize = 10,\n        color    = INK_SOFT,\n        align    = [(h, v)],\n    )\nend\n\n# Labels for arbitrary complex numbers — symbolic name + rectangular form annotation\nfor (r_val, i_val, lbl) in zip(re_arb, im_arb, arb_labels)\n    mag = sqrt(r_val^2 + i_val^2)\n    ox  = r_val / mag * 0.2\n    oy  = i_val / mag * 0.2\n    h   = r_val > 0 ? :left : :right\n    v   = i_val > 0 ? :bottom : :top\n    # Symbolic label\n    text!(ax, [Point2f(r_val + ox, i_val + oy)];\n        text     = [lbl],\n        fontsize = 14,\n        color    = INK,\n        align    = [(h, v)],\n    )\n    # Rectangular form — placed further out along the same radial direction\n    rect_str = i_val >= 0 ?\n        \"$(round(r_val, digits=2))+$(round(i_val, digits=2))i\" :\n        \"$(round(r_val, digits=2))$(round(i_val, digits=2))i\"\n    rox = r_val / mag * (0.2 + 0.24)\n    roy = i_val / mag * (0.2 + 0.24)\n    text!(ax, [Point2f(r_val + rox, i_val + roy)];\n        text     = [rect_str],\n        fontsize = 10,\n        color    = INK_SOFT,\n        align    = [(h, v)],\n    )\nend\n\n# Legend (lower-left inside axis)\naxislegend(ax;\n    position        = :lb,\n    backgroundcolor = ELEVATED_BG,\n    framecolor      = INK_SOFT,\n    labelcolor      = INK,\n    labelsize       = 12,\n)\n\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}