{"spec_id":"rug-basic","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nrug-basic: Basic Rug Plot\nLibrary: altair 6.2.2 | Python 3.13.14\nQuality: 87/100 | Updated: 2026-07-25\n\"\"\"\n\nimport os\n\nimport altair as alt\nimport numpy as np\nimport pandas as pd\nfrom PIL import Image\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"  # Imprint palette position 1\n\n# Data - bimodal distribution showing clustering patterns and gaps\nnp.random.seed(42)\nvalues = np.concatenate(\n    [\n        np.random.normal(25, 5, 60),  # Dense cluster around 25 ms\n        np.random.normal(55, 8, 40),  # Sparser cluster around 55 ms\n    ]\n)\n\ndf = pd.DataFrame({\"values\": values, \"y\": [0] * len(values), \"y2\": [0.6] * len(values)})\n\n# Plot\nrug = (\n    alt.Chart(df)\n    .mark_rule(strokeWidth=3, opacity=0.6, color=BRAND)\n    .encode(\n        x=alt.X(\"values:Q\", title=\"Response Time (ms)\", scale=alt.Scale(domain=[5, 80])),\n        y=alt.Y(\"y:Q\", scale=alt.Scale(domain=[0, 4]), axis=None),\n        y2=\"y2:Q\",\n    )\n)\n\nchart = (\n    rug.properties(\n        width=620, height=320, title=alt.Title(\"rug-basic · altair · anyplot.ai\", fontSize=16), background=PAGE_BG\n    )\n    .configure_view(fill=PAGE_BG, stroke=None)\n    .configure_axis(\n        domainColor=INK_SOFT,\n        tickColor=INK_SOFT,\n        gridColor=INK,\n        gridOpacity=0.10,\n        labelColor=INK_SOFT,\n        titleColor=INK,\n        labelFontSize=10,\n        titleFontSize=12,\n    )\n    .configure_title(color=INK)\n)\n\n# Save\nchart.save(f\"plot-{THEME}.png\", scale_factor=4.0)\n\n# Canvas hard contract: pad the vl-convert output up to the exact target (never crop).\nTW, TH = 3200, 1800\n_img = Image.open(f\"plot-{THEME}.png\").convert(\"RGB\")\n_w, _h = _img.size\nif _w > TW or _h > TH:\n    raise SystemExit(\n        f\"altair vl-convert produced {_w}×{_h}, exceeds target {TW}×{TH}. \"\n        f\"Shrink chart .properties(width=, height=) values and re-render.\"\n    )\nif _w < TW or _h < TH:\n    _canvas = Image.new(\"RGB\", (TW, TH), PAGE_BG)\n    _canvas.paste(_img, ((TW - _w) // 2, (TH - _h) // 2))\n    _canvas.save(f\"plot-{THEME}.png\")\n\nchart.save(f\"plot-{THEME}.html\")\n"}