{"spec_id":"cat-box-strip","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\ncat-box-strip: Box Plot with Strip Overlay\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-13\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\"\n\nBRAND = \"#009E73\"  # Okabe-Ito position 1\n\n# Data - Generate groups with different distributions to showcase features\nnp.random.seed(42)\n\ncategories = [\"Control\", \"Treatment A\", \"Treatment B\", \"Treatment C\"]\nn_points = [35, 40, 30, 45]  # Different sample sizes per group\n\n# Create varied distributions to show boxplot features\ndata = {\n    \"Control\": np.random.normal(50, 8, n_points[0]),\n    \"Treatment A\": np.random.normal(65, 12, n_points[1]),  # Higher mean, more spread\n    \"Treatment B\": np.concatenate(\n        [  # Bimodal with outliers\n            np.random.normal(45, 5, n_points[2] - 3),\n            np.array([15, 80, 82]),  # Outliers\n        ]\n    ),\n    \"Treatment C\": np.random.normal(55, 6, n_points[3]),  # Moderate\n}\n\n# Prepare data for plotting\nbox_data = [data[cat] for cat in categories]\npositions = np.arange(len(categories)) + 1\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Box plot\nax.boxplot(\n    box_data,\n    positions=positions,\n    tick_labels=categories,\n    widths=0.5,\n    patch_artist=True,\n    boxprops={\"facecolor\": BRAND, \"alpha\": 0.4, \"linewidth\": 2, \"edgecolor\": INK_SOFT},\n    medianprops={\"color\": \"#AE3030\", \"linewidth\": 3},\n    whiskerprops={\"color\": INK_SOFT, \"linewidth\": 2},\n    capprops={\"color\": INK_SOFT, \"linewidth\": 2},\n    flierprops={\n        \"marker\": \"o\",\n        \"markerfacecolor\": BRAND,\n        \"markersize\": 10,\n        \"alpha\": 0.7,\n        \"markeredgecolor\": INK_SOFT,\n        \"markeredgewidth\": 1,\n    },\n)\n\n# Strip plot overlay - add jittered points\nfor pos, cat in zip(positions, categories, strict=True):\n    y = data[cat]\n    # Jitter x positions\n    x = np.random.normal(pos, 0.08, len(y))\n    ax.scatter(x, y, s=100, alpha=0.6, color=BRAND, edgecolor=PAGE_BG, linewidth=1, zorder=3)\n\n# Style\nax.set_xlabel(\"Treatment Group\", fontsize=20, color=INK)\nax.set_ylabel(\"Response Value (score)\", fontsize=20, color=INK)\nax.set_title(\"cat-box-strip · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT, labelcolor=INK_SOFT)\n\n# Spines\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# Grid\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\n\n# Adjust y-axis to show all data including outliers\nax.set_ylim(0, 100)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}