{"spec_id":"subplot-mosaic","library":"makie","language":"julia","code":"# anyplot.ai\n# subplot-mosaic: Mosaic Subplot Layout with Varying Sizes\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\nusing Statistics: mean\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\"\nconst GRID_RGBA = RGBAf(INK.r, INK.g, INK.b, 0.15)\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# Household energy dashboard, one day at 10-minute resolution.\nn_steps = 144\ntime_hours = collect(range(0, 24; length = n_steps))\n\noutdoor_temp = 18 .+ 8 .* sin.(2π .* (time_hours .- 9) ./ 24) .+ randn(n_steps) .* 0.6\nheating_load = 0.06 .* max.(outdoor_temp .- 19, 0.0) .^ 1.5\nevening_bump = 0.5 .* (sin.(2π .* (time_hours .- 18) ./ 24) .+ 1) .^ 2\npower_draw = 0.9 .+ heating_load .+ evening_bump .+ 0.08 .* randn(n_steps)\npower_draw = max.(power_draw, 0.3)\n\ndevice_categories = [\"HVAC\", \"Water Heater\", \"Appliances\", \"Lighting\", \"Electronics\"]\ndevice_avg_draw = [1.32, 0.58, 0.44, 0.21, 0.29]\n\nhumidity = 55 .+ 10 .* sin.(2π .* (time_hours .- 3) ./ 24) .+ randn(n_steps) .* 3\nsample_idx = 1:3:n_steps\n\nperiod_labels = [\"Night\", \"Morning\", \"Afternoon\", \"Evening\"]\nperiod_bounds = [(0, 6), (6, 12), (12, 18), (18, 24)]\nperiod_avg_draw = [\n    mean(power_draw[(time_hours .>= lo) .& (time_hours .< hi)]) for (lo, hi) in period_bounds\n]\n\nelectricity_rate = 0.18  # $/kWh\ncumulative_cost = cumsum(power_draw .* (10 / 60) .* electricity_rate)\n\n# --- Plot -----------------------------------------------------------------\n# Mosaic pattern encoded via GridLayout spans (Makie has no string-mosaic\n# parser, so spans are the native equivalent of \"AAAAAA;BBBCCC;DDEEFF\"):\n#   row 1: A A A A A A   (wide overview — dominant)\n#   row 2: B B B C C C   (two medium detail panels)\n#   row 3: D D E E F F   (three small metric panels)\nfig = Figure(\n    resolution      = (1600, 900),\n    fontsize        = 14,\n    backgroundcolor = PAGE_BG,\n)\n\nLabel(\n    fig[0, 1:6],\n    \"subplot-mosaic · julia · makie · anyplot.ai\";\n    fontsize = 22,\n    color    = INK,\n    font     = :bold,\n    padding  = (0, 0, 8, 0),\n)\n\nchrome = (;\n    backgroundcolor   = PAGE_BG,\n    titlecolor        = INK,\n    xlabelcolor       = INK,\n    ylabelcolor       = INK,\n    xticklabelcolor   = INK_SOFT,\n    yticklabelcolor   = INK_SOFT,\n    xtickcolor        = INK_SOFT,\n    ytickcolor        = INK_SOFT,\n    leftspinecolor    = INK_SOFT,\n    bottomspinecolor  = INK_SOFT,\n    topspinevisible   = false,\n    rightspinevisible = false,\n    xminorgridvisible = false,\n    yminorgridvisible = false,\n)\n\nax_overview = Axis(\n    fig[1, 1:6];\n    title        = \"Household Power Draw — 24 Hours\",\n    titlesize    = 17,\n    xlabel       = \"Hour of Day\",\n    ylabel       = \"Power (kW)\",\n    xlabelsize   = 14,\n    ylabelsize   = 14,\n    xgridvisible = false,\n    ygridcolor   = GRID_RGBA,\n    chrome...,\n)\n\nax_devices = Axis(\n    fig[2, 1:3];\n    title          = \"Average Draw by Device\",\n    titlesize      = 15,\n    ylabel         = \"Power (kW)\",\n    ylabelsize     = 14,\n    xticklabelrotation = π / 6,\n    xgridvisible   = false,\n    ygridcolor     = GRID_RGBA,\n    chrome...,\n)\n\nax_temp = Axis(\n    fig[2, 4:6];\n    title       = \"Temperature vs. Draw\",\n    titlesize   = 15,\n    xlabel      = \"Outdoor Temp (°C)\",\n    ylabel      = \"Power (kW)\",\n    xlabelsize  = 14,\n    ylabelsize  = 14,\n    xgridcolor  = GRID_RGBA,\n    ygridcolor  = GRID_RGBA,\n    chrome...,\n)\n\nax_period = Axis(\n    fig[3, 1:2];\n    title          = \"Draw by Period\",\n    titlesize      = 13,\n    ylabel         = \"kW\",\n    ylabelsize     = 12,\n    xticklabelsize = 11,\n    yticklabelsize = 11,\n    xgridvisible   = false,\n    ygridvisible   = false,\n    chrome...,\n)\n\nax_cost = Axis(\n    fig[3, 3:4];\n    title          = \"Cumulative Cost\",\n    titlesize      = 13,\n    xlabel         = \"Hour\",\n    ylabel         = \"USD\",\n    xlabelsize     = 12,\n    ylabelsize     = 12,\n    xticklabelsize = 11,\n    yticklabelsize = 11,\n    xgridvisible   = false,\n    ygridvisible   = false,\n    chrome...,\n)\n\nax_humidity = Axis(\n    fig[3, 5:6];\n    title          = \"Humidity vs. Draw\",\n    titlesize      = 13,\n    xlabel         = \"Humidity (%)\",\n    ylabel         = \"kW\",\n    xlabelsize     = 12,\n    ylabelsize     = 12,\n    xticklabelsize = 11,\n    yticklabelsize = 11,\n    xgridvisible   = false,\n    ygridvisible   = false,\n    chrome...,\n)\n\n# A — wide overview: total draw with a band down to its daily floor\nband!(\n    ax_overview, time_hours, fill(minimum(power_draw), n_steps), power_draw;\n    color = (IMPRINT_PALETTE[1], 0.12),\n)\nlines!(ax_overview, time_hours, power_draw; color = IMPRINT_PALETTE[1], linewidth = 2.5)\n\n# B — medium detail: categorical bar, canonical Imprint order\nbarplot!(\n    ax_devices, 1:length(device_categories), device_avg_draw;\n    color = IMPRINT_PALETTE[1:length(device_categories)],\n    strokewidth = 0.5, strokecolor = PAGE_BG,\n)\nax_devices.xticks = (1:length(device_categories), device_categories)\n\n# C — medium detail: scatter relationship\nscatter!(\n    ax_temp, outdoor_temp, power_draw;\n    color = IMPRINT_PALETTE[6], markersize = 9, strokewidth = 0,\n)\n\n# D — small metric panel: period bars\nbarplot!(\n    ax_period, 1:length(period_labels), period_avg_draw;\n    color = IMPRINT_PALETTE[1:length(period_labels)],\n    strokewidth = 0.5, strokecolor = PAGE_BG,\n)\nax_period.xticks = (1:length(period_labels), period_labels)\n\n# E — small metric panel: cumulative cost trend\nlines!(ax_cost, time_hours, cumulative_cost; color = IMPRINT_PALETTE[7], linewidth = 2.0)\n\n# F — small metric panel: sparse scatter (subsampled for a clean small panel)\nscatter!(\n    ax_humidity, humidity[sample_idx], power_draw[sample_idx];\n    color = IMPRINT_PALETTE[8], markersize = 8, strokewidth = 0,\n)\n\nrowsize!(fig.layout, 1, Relative(0.42))\nrowsize!(fig.layout, 2, Relative(0.34))\nrowsize!(fig.layout, 3, Relative(0.24))\ncolgap!(fig.layout, 20)\nrowgap!(fig.layout, 22)\n\n# --- Save -------------------------------------------------------------------\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}