{"spec_id":"density-rug","library":"letsplot","language":"python","code":"\"\"\" anyplot.ai\ndensity-rug: Density Plot with Rug Marks\nLibrary: letsplot 4.9.0 | Python 3.13.13\nQuality: 85/100 | Updated: 2026-05-18\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nfrom lets_plot import (\n    LetsPlot,\n    aes,\n    element_line,\n    element_rect,\n    element_text,\n    geom_density,\n    geom_segment,\n    ggplot,\n    ggsave,\n    ggsize,\n    labs,\n    theme,\n    theme_minimal,\n)\n\n\nLetsPlot.setup_html()\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 - Simulated response times (ms) showing bimodal distribution\nnp.random.seed(42)\nfast_responses = np.random.normal(loc=250, scale=40, size=80)\nslow_responses = np.random.normal(loc=450, scale=60, size=40)\nresponse_times = np.concatenate([fast_responses, slow_responses])\ndf = pd.DataFrame({\"response_time\": response_times})\n\n# Create rug data - small vertical segments at each data point\nrug_height = 0.0003\nrug_df = pd.DataFrame({\"x\": response_times, \"ymin\": 0, \"ymax\": rug_height})\n\n# Plot\nplot = (\n    ggplot()\n    + geom_density(aes(x=\"response_time\"), data=df, fill=BRAND, color=BRAND, alpha=0.4, size=1.5)\n    + geom_segment(aes(x=\"x\", xend=\"x\", y=\"ymin\", yend=\"ymax\"), data=rug_df, color=BRAND, alpha=0.6, size=1.0)\n    + labs(x=\"Response Time (ms)\", y=\"Density\", title=\"density-rug · Python · letsplot · anyplot.ai\")\n    + ggsize(1600, 900)\n    + theme_minimal()\n    + theme(\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_SOFT, size=0.3),\n        panel_grid_minor=element_line(color=INK_SOFT, size=0.2),\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),\n        plot_title=element_text(size=24, color=INK),\n    )\n)\n\n# Save\nggsave(plot, f\"plot-{THEME}.png\", path=\".\", scale=3)\nggsave(plot, f\"plot-{THEME}.html\", path=\".\")\n"}