{"spec_id":"cat-box-strip","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\ncat-box-strip: Box Plot with Strip Overlay\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 83/100 | Updated: 2026-05-13\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\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\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\nBRAND = \"#009E73\"  # Okabe-Ito position 1\nSERIES2 = \"#C475FD\"  # Okabe-Ito position 2\n\n# Data - Exam scores across different study methods\nnp.random.seed(42)\n\ncategories = [\"Methods A\", \"Method B\", \"Method C\", \"Method D\"]\nn_per_group = [35, 40, 30, 45]\n\ndata = []\n# Method A: Normal distribution, moderate spread\ndata.extend([{\"Method\": \"Method A\", \"Score\": v} for v in np.random.normal(72, 8, n_per_group[0])])\n# Method B: Higher scores, tighter spread\ndata.extend([{\"Method\": \"Method B\", \"Score\": v} for v in np.random.normal(85, 5, n_per_group[1])])\n# Method C: Lower scores with some outliers\nscores_c = np.concatenate([np.random.normal(58, 10, n_per_group[2] - 3), [25, 28, 95]])\ndata.extend([{\"Method\": \"Method C\", \"Score\": v} for v in scores_c])\n# Method D: Bimodal distribution\nscores_d = np.concatenate(\n    [np.random.normal(65, 6, n_per_group[3] // 2), np.random.normal(80, 6, n_per_group[3] - n_per_group[3] // 2)]\n)\ndata.extend([{\"Method\": \"Method D\", \"Score\": v} for v in scores_d])\n\ndf = pd.DataFrame(data)\n\n# Create figure\nfig = go.Figure()\n\n# Add box plots for each category using native boxpoints\nfor cat in categories:\n    cat_data = df[df[\"Method\"] == cat][\"Score\"]\n    fig.add_trace(\n        go.Box(\n            y=cat_data,\n            name=cat,\n            boxmean=False,\n            marker_color=BRAND,\n            line=dict(color=BRAND, width=2),\n            fillcolor=\"rgba(0, 158, 115, 0.15)\",\n            boxpoints=\"all\",\n            jitter=0.3,\n            pointpos=-1.5,\n            marker=dict(size=10, color=BRAND, opacity=0.7, line=dict(color=PAGE_BG, width=0.5)),\n            showlegend=False,\n        )\n    )\n\n# Update layout with theme-adaptive styling\nfig.update_layout(\n    title=dict(text=\"cat-box-strip · plotly · anyplot.ai\", font=dict(size=28, color=INK)),\n    xaxis=dict(\n        title=dict(text=\"Study Method\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n    ),\n    yaxis=dict(\n        title=dict(text=\"Exam Score (%)\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        gridwidth=1,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font=dict(color=INK),\n    showlegend=False,\n    margin=dict(l=80, r=50, t=100, b=80),\n    hovermode=\"closest\",\n)\n\n# Save as PNG and HTML\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}