{"spec_id":"density-rug","library":"plotnine","language":"python","code":"\"\"\" anyplot.ai\ndensity-rug: Density Plot with Rug Marks\nLibrary: plotnine 0.15.4 | Python 3.13.13\nQuality: 93/100 | Updated: 2026-05-18\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom plotnine import (\n    aes,\n    element_line,\n    element_rect,\n    element_text,\n    geom_density,\n    geom_rug,\n    ggplot,\n    labs,\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\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Response times for a web API (bimodal distribution with outliers)\nnp.random.seed(42)\nfast_responses = np.random.normal(loc=120, scale=25, size=180)\nslow_responses = np.random.normal(loc=280, scale=40, size=70)\nresponse_times = np.concatenate([fast_responses, slow_responses])\nresponse_times = response_times[response_times > 0]\n# Add more extreme outliers to showcase rug mark utility\noutliers = np.random.uniform(400, 600, size=15)\nresponse_times = np.concatenate([response_times, outliers])\n\ndf = pd.DataFrame({\"response_time\": response_times})\n\n# Plot\nplot = (\n    ggplot(df, aes(x=\"response_time\"))\n    + geom_density(fill=BRAND, alpha=0.5, color=BRAND, size=1.5)\n    + geom_rug(alpha=0.5, sides=\"b\", size=1.4, color=BRAND, length=0.04)\n    + labs(x=\"Response Time (ms)\", y=\"Density\", title=\"density-rug · Python · plotnine · anyplot.ai\")\n    + theme_minimal()\n    + theme(\n        figure_size=(16, 9),\n        plot_background=element_rect(fill=PAGE_BG, color=PAGE_BG),\n        panel_background=element_rect(fill=PAGE_BG),\n        panel_grid_major=element_line(color=INK, size=0.3, alpha=0.12),\n        panel_grid_minor=element_line(color=INK, size=0.2, alpha=0.06),\n        panel_border=element_rect(color=INK_SOFT, fill=None, size=0.3),\n        axis_title=element_text(size=20, color=INK),\n        axis_text=element_text(size=16, color=INK_SOFT),\n        axis_line=element_line(color=INK_SOFT, size=0.5),\n        plot_title=element_text(size=24, color=INK),\n    )\n)\n\n# Save\nplot.save(f\"plot-{THEME}.png\", dpi=300, verbose=False)\n"}