{"spec_id":"density-rug","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\ndensity-rug: Density Plot with Rug Marks\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 94/100 | Updated: 2026-05-18\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\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 - Sensor measurement errors (single-peak exponential decay)\nnp.random.seed(17)\n# Most measurements have small errors, few have large errors (exponential distribution)\n# This represents measurement precision in scientific instruments\nerrors = np.random.exponential(scale=15, size=250)\n# Add a small noise component to make it slightly more realistic\nerrors = errors + np.random.normal(0, 2, size=250)\n# Clip to realistic bounds (0-80)\nerrors = np.clip(errors, 0, 80)\n\n# Configure seaborn theme\nsns.set_theme(\n    style=\"ticks\",\n    rc={\n        \"figure.facecolor\": PAGE_BG,\n        \"axes.facecolor\": PAGE_BG,\n        \"axes.edgecolor\": INK_SOFT,\n        \"axes.labelcolor\": INK,\n        \"text.color\": INK,\n        \"xtick.color\": INK_SOFT,\n        \"ytick.color\": INK_SOFT,\n        \"grid.color\": INK,\n        \"grid.alpha\": 0.10,\n    },\n)\n\n# Create figure\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\n\n# Plot KDE with fill\nsns.kdeplot(data=errors, ax=ax, fill=True, alpha=0.35, color=BRAND, linewidth=3, bw_adjust=0.9)\n\n# Add rug plot\nsns.rugplot(data=errors, ax=ax, color=BRAND, alpha=0.5, height=0.04, linewidth=1.2)\n\n# Styling\nax.set_xlabel(\"Measurement Error (μm)\", fontsize=20, color=INK)\nax.set_ylabel(\"Density\", fontsize=20, color=INK)\nax.set_title(\"density-rug · Python · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Grid styling (y-axis only, subtle)\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\nax.set_axisbelow(True)\n\n# Remove top and right spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nfor spine in (\"left\", \"bottom\"):\n    ax.spines[spine].set_color(INK_SOFT)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}