{"spec_id":"scatter-marginal","library":"makie","language":"julia","code":"# anyplot.ai\n# scatter-marginal: Scatter Plot with Marginal Distributions\n# Library: makie 0.21.9 | Julia 1.11.9\n# Quality: 90/100 | Created: 2026-09-09\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 INK      = THEME == \"light\" ? colorant\"#1A1A17\" : colorant\"#F0EFE8\"\nconst INK_SOFT = THEME == \"light\" ? colorant\"#4A4A44\" : colorant\"#B8B7B0\"\n\nconst IMPRINT_PALETTE = [\n    colorant\"#009E73\", colorant\"#C475FD\", colorant\"#4467A3\", colorant\"#BD8233\",\n    colorant\"#AE3030\", colorant\"#2ABCCD\", colorant\"#954477\", colorant\"#99B314\",\n]\nconst BRAND = IMPRINT_PALETTE[1]\n\n# --- Data ---------------------------------------------------------------------\n# Forestry measurements: trunk diameter (right-skewed, small trees are common,\n# large ones rarer) and the resulting tree height, correlated with diameter.\nn = 400\ntrunk_diameter_cm = 28.0 .* exp.(0.28 .* randn(n))\ntree_height_m = 4.5 .+ 0.55 .* trunk_diameter_cm .+ 2.2 .* randn(n)\n\n# --- Plot ----------------------------------------------------------------------\ntitle_str = \"scatter-marginal · julia · makie · anyplot.ai\"\n\nfig = Figure(\n    resolution      = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nmain_ax = Axis(\n    fig[3, 1];\n    xlabel            = \"Trunk Diameter (cm)\",\n    ylabel            = \"Tree Height (m)\",\n    xlabelcolor       = INK,\n    ylabelcolor       = INK,\n    xticklabelcolor   = INK_SOFT,\n    yticklabelcolor   = INK_SOFT,\n    xtickcolor        = INK_SOFT,\n    ytickcolor        = INK_SOFT,\n    xlabelsize        = 14,\n    ylabelsize        = 14,\n    xticklabelsize    = 12,\n    yticklabelsize    = 12,\n    backgroundcolor   = PAGE_BG,\n    topspinevisible   = false,\n    rightspinevisible = false,\n    leftspinecolor    = INK_SOFT,\n    bottomspinecolor  = INK_SOFT,\n    xgridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    ygridcolor        = RGBAf(INK.r, INK.g, INK.b, 0.15),\n    xminorgridvisible = false,\n    yminorgridvisible = false,\n)\n\ntop_ax = Axis(\n    fig[2, 1];\n    backgroundcolor = PAGE_BG,\n)\n\nright_ax = Axis(\n    fig[3, 2];\n    backgroundcolor = PAGE_BG,\n)\n\nLabel(\n    fig[1, 1:2], title_str;\n    fontsize = 20, color = INK, font = :bold,\n)\n\nlinkxaxes!(main_ax, top_ax)\nlinkyaxes!(main_ax, right_ax)\n\nrowsize!(fig.layout, 1, Fixed(36))\nrowsize!(fig.layout, 2, Relative(0.22))\ncolsize!(fig.layout, 2, Relative(0.22))\nrowgap!(fig.layout, 8)\ncolgap!(fig.layout, 8)\n\nscatter!(\n    main_ax, trunk_diameter_cm, tree_height_m;\n    color = (BRAND, 0.55), markersize = 8, strokewidth = 0,\n)\n\nhist!(top_ax, trunk_diameter_cm; bins = 30, color = (BRAND, 0.35), strokewidth = 0)\nhist!(right_ax, tree_height_m; bins = 30, direction = :x, color = (BRAND, 0.35), strokewidth = 0)\n\nhidedecorations!(top_ax)\nhidedecorations!(right_ax)\nhidespines!(top_ax)\nhidespines!(right_ax)\n\n# --- Save -----------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}