{"spec_id":"rug-basic","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\nrug-basic: Basic Rug Plot\nLibrary: plotnine 0.15.7 | Python 3.13.14\nQuality: 93/100 | Updated: 2026-07-25\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    annotate,\n    element_blank,\n    element_line,\n    element_rect,\n    element_text,\n    geom_density,\n    geom_rug,\n    ggplot,\n    labs,\n    scale_x_continuous,\n    theme,\n    theme_minimal,\n)\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\"\nAMBER = \"#DDCC77\"  # Imprint semantic anchor — warning / caution, used to flag the outlier region\n\n# Data - simulated response times with realistic clustering and gaps\nnp.random.seed(42)\ncluster1 = np.random.normal(150, 20, 40)\ncluster2 = np.random.normal(280, 35, 30)\ncluster3 = np.random.normal(450, 50, 20)\noutliers = np.array([620, 680, 750, 820])\n\nvalues = np.concatenate([cluster1, cluster2, cluster3, outliers])\ndf = pd.DataFrame({\"response_time\": values})\noutlier_start = 550  # visual boundary separating the main mass from the sparse tail\n\n# Plot\nanyplot_theme = theme(\n    figure_size=(8, 4.5),\n    plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n    panel_background=element_rect(fill=PAGE_BG),\n    panel_grid_major_x=element_blank(),\n    panel_grid_minor_x=element_blank(),\n    panel_grid_major_y=element_blank(),\n    panel_grid_minor_y=element_blank(),\n    panel_border=element_blank(),\n    axis_line_x=element_line(color=INK_SOFT, size=0.5),\n    axis_title_x=element_text(size=10, color=INK),\n    axis_title_y=element_blank(),\n    axis_text_x=element_text(size=8, color=INK_SOFT),\n    axis_text_y=element_blank(),\n    axis_ticks_major_y=element_blank(),\n    plot_title=element_text(size=12, color=INK),\n    plot_subtitle=element_text(size=8, color=INK_SOFT),\n)\n\nplot = (\n    ggplot(df, aes(x=\"response_time\"))\n    # Subtle amber tint calls out the sparse outlier tail against the three-cluster mass\n    + annotate(\n        \"rect\",\n        xmin=outlier_start,\n        xmax=float(values.max()) + 40,\n        ymin=-float(\"inf\"),\n        ymax=float(\"inf\"),\n        fill=AMBER,\n        alpha=0.08,\n    )\n    + annotate(\n        \"text\",\n        x=outlier_start + 10,\n        y=float(\"inf\"),\n        label=\"outliers\",\n        color=INK_SOFT,\n        size=7,\n        ha=\"left\",\n        va=\"top\",\n        fontstyle=\"italic\",\n    )\n    + geom_density(fill=BRAND, color=BRAND, alpha=0.3, size=1.0)\n    + geom_rug(alpha=0.6, sides=\"b\", size=0.8, color=BRAND)\n    + scale_x_continuous(expand=(0.03, 0))\n    + labs(\n        x=\"Response Time (ms)\",\n        y=\"\",\n        title=\"rug-basic · plotnine · anyplot.ai\",\n        subtitle=\"94 API calls — three latency clusters with a sparse slow-response tail\",\n    )\n    + theme_minimal()\n    + anyplot_theme\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=400, width=8, height=4.5, units=\"in\", verbose=False)\n"}