{"spec_id":"rug-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nrug-basic: Basic Rug Plot\nLibrary: matplotlib 3.11.1 | Python 3.13.14\nQuality: 90/100 | Updated: 2026-07-25\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nBRAND = \"#009E73\"  # Imprint palette position 1\n\n# Data - trimodal response times with outliers to show clustering, gaps, and extremes\nnp.random.seed(42)\ncore_values = np.concatenate(\n    [\n        np.random.normal(25, 4, 50),  # Tight cluster around 25 ms\n        np.random.normal(55, 7, 35),  # Wider cluster around 55 ms\n        np.random.normal(75, 3, 15),  # Small cluster at high end\n    ]\n)\noutliers = np.array([5.2, 7.8, 95.3, 98.6])  # Extreme outliers at both ends\nvalues = np.concatenate([core_values, outliers])\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Rug plot using ax.eventplot() — matplotlib's top-level API for 1D event distributions\n# Kept small (linelengths=0.3) so marks read as ticks, not bars; alpha lowered so\n# individual ticks stay distinguishable even in the densest cluster\nax.eventplot(\n    values, orientation=\"horizontal\", lineoffsets=0.5, linelengths=0.3, linewidths=2.0, colors=BRAND, alpha=0.55\n)\n\nax.set_xlim(-2, 107)\nax.set_ylim(0.25, 1.0)  # trims the dead space below the ticks down to the x-axis\n\n# Hide y-axis — rug plots focus on the x-distribution only\nax.set_yticks([])\nax.spines[\"left\"].set_visible(False)\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"bottom\"].set_color(INK_SOFT)\n\n# Cluster annotations, anchored with arrows to the rug-mark tops (bridges the\n# gap between the callout text and the data instead of floating above it)\narrow_style = {\"arrowstyle\": \"-\", \"color\": INK_MUTED, \"lw\": 1, \"alpha\": 0.6}\nax.annotate(\n    \"Dense cluster\\n(n=50)\",\n    xy=(25, 0.65),\n    xytext=(25, 0.9),\n    ha=\"center\",\n    fontsize=9,\n    color=INK_SOFT,\n    arrowprops=arrow_style,\n)\nax.annotate(\n    \"Wider spread\\n(n=35)\",\n    xy=(55, 0.65),\n    xytext=(55, 0.9),\n    ha=\"center\",\n    fontsize=9,\n    color=INK_SOFT,\n    arrowprops=arrow_style,\n)\nax.annotate(\n    \"Small group\\n(n=15)\",\n    xy=(75, 0.65),\n    xytext=(75, 0.9),\n    ha=\"center\",\n    fontsize=9,\n    color=INK_SOFT,\n    arrowprops=arrow_style,\n)\n\n# Outlier callouts at both extremes\nax.annotate(\n    \"outliers\",\n    xy=(6.5, 0.65),\n    xytext=(6.5, 0.9),\n    ha=\"center\",\n    fontsize=8,\n    color=INK_MUTED,\n    style=\"italic\",\n    arrowprops=arrow_style,\n)\nax.annotate(\n    \"outliers\",\n    xy=(96.9, 0.65),\n    xytext=(96.9, 0.9),\n    ha=\"center\",\n    fontsize=8,\n    color=INK_MUTED,\n    style=\"italic\",\n    arrowprops=arrow_style,\n)\n\n# Labels and title\nax.set_xlabel(\"Response Time (ms)\", fontsize=10, color=INK)\nax.set_title(\"rug-basic · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK, pad=14)\nax.tick_params(axis=\"x\", labelsize=8, colors=INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)  # bbox_inches MUST stay default (None)\n"}