{"spec_id":"box-notched","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nbox-notched: Notched Box Plot\nLibrary: seaborn 0.13.2 | Python 3.13.15\nQuality: 91/100 | Updated: 2026-08-18\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\n\n\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\n# Imprint palette — canonical order, first series always #009E73\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\"]\n\n# Data - Test score distributions across student cohorts\nnp.random.seed(42)\n\ncohorts = [\"Cohort A\", \"Cohort B\", \"Cohort C\", \"Cohort D\"]\ndata = []\n\n# Cohort A: strong performance, tight cluster\ndata.extend([{\"Cohort\": \"Cohort A\", \"Test Score\": val} for val in np.clip(np.random.normal(82, 8, 85), 0, 100)])\n\n# Cohort B: moderate performance, some high outliers\ncohort_b_base = np.clip(np.random.normal(75, 12, 75), 0, 100)\ncohort_b_outliers = np.array([95, 96, 98])\ndata.extend([{\"Cohort\": \"Cohort B\", \"Test Score\": val} for val in np.concatenate([cohort_b_base, cohort_b_outliers])])\n\n# Cohort C: wide variation in performance\ndata.extend([{\"Cohort\": \"Cohort C\", \"Test Score\": val} for val in np.clip(np.random.normal(70, 15, 80), 0, 100)])\n\n# Cohort D: lower performance, tight clustering\ndata.extend([{\"Cohort\": \"Cohort D\", \"Test Score\": val} for val in np.clip(np.random.normal(68, 9, 70), 0, 100)])\n\ndf = pd.DataFrame(data)\n\n# Setup 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.15,\n        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Create plot\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\n\n# Notched box plot on the Imprint palette; mean diamonds sit alongside the\n# notched median so a skewed mean (e.g. Cohort B's high-scoring outliers)\n# reads at a glance without needing text annotations.\nsns.boxplot(\n    data=df,\n    x=\"Cohort\",\n    y=\"Test Score\",\n    hue=\"Cohort\",\n    palette=IMPRINT[: len(cohorts)],\n    notch=True,\n    width=0.5,\n    linewidth=1.6,\n    boxprops={\"alpha\": 0.88},\n    medianprops={\"color\": INK, \"linewidth\": 1.8},\n    whiskerprops={\"color\": INK_SOFT},\n    capprops={\"color\": INK_SOFT},\n    showmeans=True,\n    meanprops={\"marker\": \"D\", \"markerfacecolor\": ELEVATED_BG, \"markeredgecolor\": INK, \"markersize\": 7},\n    fliersize=6,\n    flierprops={\"marker\": \"o\", \"markerfacecolor\": INK_SOFT, \"markeredgecolor\": INK, \"alpha\": 0.6},\n    ax=ax,\n    legend=False,\n)\n\n# Styling\nax.set_title(\"box-notched · python · seaborn · anyplot.ai\", fontsize=12, fontweight=\"medium\", color=INK)\nax.set_xlabel(\"Student Cohort\", fontsize=10, color=INK)\nax.set_ylabel(\"Test Score (%)\", fontsize=10, color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\n\n# Remove top and right spines\nax.spines[\"top\"].set_visible(False)\nax.spines[\"right\"].set_visible(False)\nax.spines[\"left\"].set_color(INK_SOFT)\nax.spines[\"bottom\"].set_color(INK_SOFT)\n\n# Grid styling\nax.yaxis.grid(True, alpha=0.15, linewidth=0.8, color=INK)\nax.set_axisbelow(True)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}