{"spec_id":"violin-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nviolin-basic: Basic Violin Plot\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-29\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\"\nINK_MUTED = \"#6B6A63\" if THEME == \"light\" else \"#A8A79F\"\n\n# Imprint palette — canonical order, first series always #009E73\nIMPRINT_PALETTE = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\"]\n\n# Data — daily temperature readings (°C) across four climate regions\nnp.random.seed(42)\nregions = [\"North\", \"South\", \"East\", \"West\"]\nrecords = []\n\nfor region in regions:\n    if region == \"North\":\n        # Cold region: compact distribution\n        temps = np.random.normal(8, 4, 200)\n    elif region == \"South\":\n        # Warm region: broader spread\n        temps = np.random.normal(24, 6, 200)\n    elif region == \"East\":\n        # Continental: bimodal (cold winters + hot summers) — showcases KDE strength\n        temps = np.concatenate([np.random.normal(4, 3, 100), np.random.normal(28, 4, 100)])\n    else:\n        # Coastal: mild with occasional heat events\n        temps = np.concatenate([np.random.normal(16, 3, 160), np.random.normal(26, 2, 40)])\n    for t in temps:\n        records.append({\"Region\": region, \"Temperature (°C)\": t})\n\ndf = pd.DataFrame(records)\n\n# Canvas — 3200 × 1800 px (landscape 16:9)\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\nfig, ax = plt.subplots(figsize=(8, 4.5), dpi=400, facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Violin plot\nsns.violinplot(\n    data=df,\n    x=\"Region\",\n    y=\"Temperature (°C)\",\n    hue=\"Region\",\n    palette=IMPRINT_PALETTE,\n    inner=\"box\",\n    cut=0,\n    linewidth=1.2,\n    saturation=1.0,\n    legend=False,\n    ax=ax,\n)\n\n# Stripplot overlay — signature seaborn layering pattern\nsns.stripplot(\n    data=df,\n    x=\"Region\",\n    y=\"Temperature (°C)\",\n    hue=\"Region\",\n    palette=IMPRINT_PALETTE,\n    dodge=False,\n    jitter=0.2,\n    size=2.5,\n    alpha=0.25,\n    legend=False,\n    ax=ax,\n)\n\n# Style\ntitle = \"violin-basic · python · seaborn · anyplot.ai\"\nax.set_xlabel(\"Region\", fontsize=10, color=INK)\nax.set_ylabel(\"Temperature (°C)\", fontsize=10, color=INK)\nax.set_title(title, fontsize=12, fontweight=\"medium\", color=INK)\nax.tick_params(axis=\"both\", labelsize=8, colors=INK_SOFT)\n\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\nax.yaxis.grid(True, linewidth=0.8)\nax.set_axisbelow(True)\n\n# Annotation: highlight the bimodal East distribution (the key storytelling insight)\nax.annotate(\n    \"Bimodal: cold winters\\n& hot summers\",\n    xy=(2, 27),\n    xytext=(2.55, 37),\n    fontsize=7.5,\n    color=INK_MUTED,\n    ha=\"left\",\n    va=\"center\",\n    arrowprops={\"arrowstyle\": \"-|>\", \"color\": INK_MUTED, \"lw\": 0.9},\n)\n\n# Save — no bbox_inches='tight' (seaborn canvas contract: figsize×dpi sets exact target)\nplt.savefig(f\"plot-{THEME}.png\", dpi=400, facecolor=PAGE_BG)\n"}