{"spec_id":"strip-basic","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nstrip-basic: Basic Strip Plot\nLibrary: matplotlib 3.11.1 | Python 3.13.14\nQuality: 93/100 | Updated: 2026-08-05\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\nAMBER = \"#DDCC77\"  # semantic anchor — warning / caution\n\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data — shaft outer-diameter inspection across four production lines (mm)\n# Target 25.000mm +/- 0.050mm tolerance; Line C has drifted high with a wider\n# spread, the kind of tooling-wear signal a strip plot is well suited to reveal.\nnp.random.seed(42)\n\nlines = [\"Line A\", \"Line B\", \"Line C\", \"Line D\"]\ndistributions = {\n    \"Line A\": (25.002, 0.015, 60),\n    \"Line B\": (24.995, 0.018, 55),\n    \"Line C\": (25.038, 0.035, 48),\n    \"Line D\": (24.998, 0.020, 52),\n}\nflagged_line = \"Line C\"\n\nmeasurements = {line: np.random.normal(mean, std, n) for line, (mean, std, n) in distributions.items()}\n\n# Plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Tolerance band gives the strip plot a reference frame for \"in spec\" vs \"out of spec\"\nax.axhspan(24.95, 25.05, color=INK_MUTED, alpha=0.06, zorder=0)\nax.axhline(25.000, color=INK_MUTED, linewidth=1, linestyle=\"--\", alpha=0.6, zorder=1)\n\nfor i, line in enumerate(lines):\n    values = measurements[line]\n    color = AMBER if line == flagged_line else IMPRINT_PALETTE[i]\n\n    jitter = np.random.uniform(-0.18, 0.18, len(values))\n    ax.scatter(i + jitter, values, s=110, alpha=0.65, color=color, edgecolors=PAGE_BG, linewidth=0.5, zorder=3)\n\n    mean_val = values.mean()\n    line_color = AMBER if line == flagged_line else INK\n    ax.hlines(mean_val, i - 0.32, i + 0.32, colors=line_color, linewidth=2.5, zorder=4)\n\n# Callout on the flagged line — the visual hierarchy the previous review asked for.\n# Anchored in the open upper-left region (Lines A/B stay well below 25.06mm) so\n# the box never crowds the canvas edge.\nflagged_mean = measurements[flagged_line].mean()\nflagged_i = lines.index(flagged_line)\nax.annotate(\n    f\"{flagged_line}: +{flagged_mean - 25.0:.3f}mm above target,\\n~2x spread — check tooling wear\",\n    xy=(flagged_i - 0.35, flagged_mean + 0.01),\n    xytext=(0.35, 25.098),\n    fontsize=10,\n    color=INK_SOFT,\n    ha=\"left\",\n    va=\"center\",\n    arrowprops={\"arrowstyle\": \"-\", \"color\": INK_SOFT, \"linewidth\": 0.8},\n    bbox={\"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.9, \"boxstyle\": \"round,pad=0.4\"},\n)\n\n# Style\nax.set_xticks(range(len(lines)))\nax.set_xticklabels(lines)\nax.set_xlabel(\"Production Line\", fontsize=10, color=INK)\nax.set_ylabel(\"Shaft Diameter (mm)\", fontsize=10, color=INK)\nax.set_title(\"strip-basic · python · matplotlib · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT, labelcolor=INK_SOFT)\nax.set_xlim(-0.6, len(lines) - 0.2)\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\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\nfig.subplots_adjust(left=0.1, right=0.97, top=0.9, bottom=0.13)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}