{"spec_id":"violin-box","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nviolin-box: Violin Plot with Embedded Box Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-12\n\"\"\"\n\nimport importlib\nimport os\nimport sys\n\n\n# Avoid importing from local directory\nfor path in list(sys.path):\n    if \"violin-box\" in path or \"implementations\" in path:\n        sys.path.remove(path)\n\nmatplotlib = importlib.import_module(\"matplotlib\")\nplt = importlib.import_module(\"matplotlib.pyplot\")\nnp = importlib.import_module(\"numpy\")\npd = importlib.import_module(\"pandas\")\nsns = importlib.import_module(\"seaborn\")\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\n# Okabe-Ito palette - first series always #009E73\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data - Product quality scores across manufacturing batches\nnp.random.seed(42)\n\n# Create varied distributions for each batch to demonstrate violin plot value\nbatch_a = np.random.normal(75, 8, 120)  # Normal, centered around 75\nbatch_b = np.concatenate([np.random.normal(60, 5, 60), np.random.normal(80, 5, 60)])  # Bimodal\nbatch_c = np.random.exponential(10, 120) + 50  # Right-skewed\nbatch_d = 95 - np.random.exponential(10, 120)  # Left-skewed\n\n# Combine into DataFrame\ndf = pd.DataFrame(\n    {\n        \"Quality Score\": np.concatenate([batch_a, batch_b, batch_c, batch_d]),\n        \"Batch\": [\"Batch A\"] * 120 + [\"Batch B\"] * 120 + [\"Batch C\"] * 120 + [\"Batch D\"] * 120,\n    }\n)\n\n# Configure seaborn theme with theme-adaptive chrome\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        \"legend.facecolor\": ELEVATED_BG,\n        \"legend.edgecolor\": INK_SOFT,\n    },\n)\n\n# Create figure\nfig, ax = plt.subplots(figsize=(16, 9))\n\n# Create violin plot with embedded box plot\nsns.violinplot(\n    data=df,\n    x=\"Batch\",\n    y=\"Quality Score\",\n    hue=\"Batch\",\n    palette=IMPRINT,\n    inner=\"box\",\n    linewidth=2,\n    saturation=0.9,\n    legend=False,\n    ax=ax,\n)\n\n# Styling\nax.set_title(\"violin-box · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", pad=20)\nax.set_xlabel(\"Manufacturing Batch\", fontsize=20, color=INK)\nax.set_ylabel(\"Quality Score (0-100)\", fontsize=20, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\nax.grid(True, alpha=0.15, axis=\"y\", linewidth=0.8)\nax.set_ylim(30, 100)\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\n# Save to script directory\nscript_dir = os.path.dirname(os.path.abspath(__file__))\noutput_path = os.path.join(script_dir, f\"plot-{THEME}.png\")\n\nplt.tight_layout()\nplt.savefig(output_path, dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}