{"spec_id":"hexbin-basic","library":"makie","language":"julia","code":"# anyplot.ai\n# hexbin-basic: Basic Hexbin Plot\n# Library: makie 0.24.16 | Julia 1.13.4\n# Quality: 84/100 | Updated: 2026-11-27\n\nusing CairoMakie\nusing Colors\nusing DataFrames\nusing Random\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\"\n\n# Imprint sequential ramp (fields: colored cells fill the plot)\nconst ANYPLOT_SEQ_FIELDS = THEME == \"light\" ?\n    cgrad([colorant\"#66E2B2\", colorant\"#009E73\", colorant\"#024582\", colorant\"#351E45\"], [0.0, 0.369, 0.803, 1.0]) :\n    cgrad([colorant\"#404C02\", colorant\"#009E73\", colorant\"#CDD9FF\"], [0.0, 0.487, 1.0])\n\n# Columns: set these to your table's column names\nconst LONGITUDE = \"Longitude (relative km)\"  # role: x\nconst LATITUDE = \"Latitude (relative km)\"    # role: y\n\n# Data: simulated urban GPS coordinates with clustered hotspots (12000 points)\nRandom.seed!(42)\ncenters = [(0.0, 0.0, 0.4, 0.4), (-2.0, 2.2, 0.5, 0.4), (2.4, 0.6, 0.5, 0.4), (0.4, -2.5, 0.45, 0.4)]\nsizes = [5000, 2500, 2500, 2000]\ndf = DataFrame(\n    LONGITUDE => reduce(vcat, [randn(n) .* c[3] .+ c[1] for (c, n) in zip(centers, sizes)]),\n    LATITUDE => reduce(vcat, [randn(n) .* c[4] .+ c[2] for (c, n) in zip(centers, sizes)]),\n)\n\n# Plot\n# Figure\nfig = Figure(\n    size            = (1600, 900),\n    fontsize        = 16,\n    backgroundcolor = PAGE_BG,\n)\n\nax = Axis(\n    fig[1, 1];\n    title              = \"hexbin-basic · julia · makie · anyplot.ai\",\n    titlesize          = 24,\n    titlecolor         = INK,\n    xlabel             = LONGITUDE,\n    ylabel             = LATITUDE,\n    xlabelsize         = 18,\n    ylabelsize         = 18,\n    xlabelcolor        = INK,\n    ylabelcolor        = INK,\n    xticklabelsize     = 15,\n    yticklabelsize     = 15,\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         = RGBAf(INK.r, INK.g, INK.b, 0.12f0),\n    ygridcolor         = RGBAf(INK.r, INK.g, INK.b, 0.12f0),\n    xminorgridvisible  = false,\n    yminorgridvisible  = false,\n)\n\n# Log colorscale surfaces peripheral mid-density clusters that would otherwise wash out\nhb = hexbin!(ax, df[!, LONGITUDE], df[!, LATITUDE];\n    bins        = 50,\n    colormap    = ANYPLOT_SEQ_FIELDS,\n    colorscale  = log10,\n    strokewidth = 0,\n)\n\n# Colorbar with log-scale ticks\nColorbar(fig[1, 2], hb;\n    label          = \"Point count (log scale)\",\n    labelsize      = 18,\n    labelcolor     = INK,\n    ticklabelsize  = 15,\n    ticklabelcolor = INK_SOFT,\n    tickcolor      = INK_SOFT,\n    ticks          = LogTicks(0:3),\n    width          = 22,\n)\n\ncolsize!(fig.layout, 1, Relative(0.87))\ncolgap!(fig.layout, 14)\n\n# Save\nsave(\"plot-$(THEME).png\", fig; px_per_unit = 2)\n"}