{"spec_id":"density-rug","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ndensity-rug: Density Plot with Rug Marks\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 90/100 | Updated: 2026-05-18\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.stats import gaussian_kde\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\"  # Okabe-Ito position 1\n\n# Data - Response times (ms) for a web service with bimodal distribution\nnp.random.seed(42)\n# Mix of fast responses (cache hits) and slower responses (database queries)\nfast_responses = np.random.normal(loc=45, scale=8, size=80)\nslow_responses = np.random.normal(loc=120, scale=25, size=70)\nresponse_times = np.concatenate([fast_responses, slow_responses])\nresponse_times = response_times[response_times > 0]  # Keep only positive values\n\n# Compute KDE\nkde = gaussian_kde(response_times, bw_method=\"scott\")\nx_range = np.linspace(response_times.min() - 10, response_times.max() + 10, 500)\ndensity = kde(x_range)\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# KDE curve with fill\nax.fill_between(x_range, density, alpha=0.4, color=BRAND)\nax.plot(x_range, density, color=BRAND, linewidth=3)\n\n# Rug marks along x-axis\nrug_height = 0.015 * density.max()\nfor val in response_times:\n    ax.plot([val, val], [0, rug_height], color=BRAND, alpha=0.6, linewidth=2)\n\n# Style\nax.set_xlabel(\"Response Time (ms)\", fontsize=20, color=INK)\nax.set_ylabel(\"Density\", fontsize=20, color=INK)\nax.set_title(\"density-rug · Python · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor s in (\"left\", \"bottom\"):\n    ax.spines[s].set_color(INK_SOFT)\n\n# Set y-axis to start at 0 with some padding at top\nax.set_ylim(bottom=-0.0005, top=density.max() * 1.1)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}