{"spec_id":"violin-split","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nviolin-split: Split Violin Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 92/100 | Updated: 2026-05-08\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\nimport seaborn as sns\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\n# Okabe-Ito palette - first series always #009E73, second is #C475FD\nBRAND = \"#009E73\"\nSECONDARY = \"#C475FD\"\n\n# Data - Salary comparison between genders across departments with varied distributions\nnp.random.seed(42)\n\ndepartments = [\"Engineering\", \"Marketing\", \"Sales\", \"Finance\"]\ngenders = [\"Male\", \"Female\"]\n\ndata = []\n# Create diverse salary distributions with distinct patterns per department\n# to better showcase split violin comparative power\nsalary_params = {\n    \"Engineering\": {\"Male\": (105000, 18000), \"Female\": (88000, 12000)},\n    \"Marketing\": {\"Male\": (68000, 10000), \"Female\": (78000, 14000)},\n    \"Sales\": {\"Male\": (72000, 22000), \"Female\": (62000, 14000)},\n    \"Finance\": {\"Male\": (82000, 11000), \"Female\": (85000, 16000)},\n}\n\nfor dept in departments:\n    for gender in genders:\n        mean, std = salary_params[dept][gender]\n        n_samples = np.random.randint(100, 160)\n        salaries = np.random.normal(mean, std, n_samples)\n        salaries = np.clip(salaries, 25000, 185000)\n        for sal in salaries:\n            data.append({\"Department\": dept, \"Gender\": gender, \"Salary\": sal})\n\ndf = pd.DataFrame(data)\n\n# Set seaborn theme with theme-adaptive colors\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# Plot\nfig, ax = plt.subplots(figsize=(16, 9))\n\nsns.violinplot(\n    data=df,\n    x=\"Department\",\n    y=\"Salary\",\n    hue=\"Gender\",\n    split=True,\n    inner=\"quart\",\n    palette={\"Male\": BRAND, \"Female\": SECONDARY},\n    linewidth=1.5,\n    ax=ax,\n)\n\n# Style\nax.set_title(\"violin-split · seaborn · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK, pad=20)\nax.set_xlabel(\"Department\", fontsize=20, color=INK)\nax.set_ylabel(\"Annual Salary ($)\", fontsize=20, color=INK)\nax.tick_params(axis=\"both\", labelsize=16, colors=INK_SOFT)\n\n# Format y-axis as currency\nax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, p: f\"${x / 1000:.0f}K\"))\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# Grid - both axes for better readability\nax.xaxis.grid(False)\nax.yaxis.grid(True, alpha=0.10, linewidth=0.8, color=INK)\nax.set_axisbelow(True)\n\n# Legend styling\nlegend = ax.legend(title=\"Gender\", fontsize=16, title_fontsize=18, loc=\"upper right\", framealpha=0.95)\nlegend.get_frame().set_facecolor(ELEVATED_BG)\nlegend.get_frame().set_edgecolor(INK_SOFT)\nlegend.get_title().set_color(INK)\nfor text in legend.get_texts():\n    text.set_color(INK)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}