{"spec_id":"venn-basic","library":"seaborn","language":"python","code":"\"\"\" anyplot.ai\nvenn-basic: Venn Diagram\nLibrary: seaborn 0.13.2 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-11\n\"\"\"\n\nimport os\n\nimport matplotlib.patches as mpatches\nimport matplotlib.pyplot as plt\nimport numpy as np\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# Okabe-Ito palette (first series always #009E73)\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\"]\n\nnp.random.seed(42)\n\n# Data - Cloud platform adoption across organizations\n# Set A: AWS users, Set B: Google Cloud users, Set C: Azure users\nset_labels = [\"AWS\", \"Google Cloud\", \"Azure\"]\nset_sizes = [120, 95, 75]  # Total in each group\n# Overlaps: AB=35, AC=28, BC=22, ABC=12\nintersections = {\"AB\": 35, \"AC\": 28, \"BC\": 22, \"ABC\": 12}\n\n# Calculate exclusive counts for each region\nonly_a = set_sizes[0] - intersections[\"AB\"] - intersections[\"AC\"] + intersections[\"ABC\"]\nonly_b = set_sizes[1] - intersections[\"AB\"] - intersections[\"BC\"] + intersections[\"ABC\"]\nonly_c = set_sizes[2] - intersections[\"AC\"] - intersections[\"BC\"] + intersections[\"ABC\"]\nab_only = intersections[\"AB\"] - intersections[\"ABC\"]\nac_only = intersections[\"AC\"] - intersections[\"ABC\"]\nbc_only = intersections[\"BC\"] - intersections[\"ABC\"]\nabc = intersections[\"ABC\"]\n\n# Total unique organizations using inclusion-exclusion principle\ntotal_orgs = sum(set_sizes) - sum(intersections.values()) + intersections[\"ABC\"]\n\n# Set seaborn style with theme-adaptive colors\nsns.set_theme(\n    style=\"white\",\n    rc={\"figure.facecolor\": PAGE_BG, \"axes.facecolor\": PAGE_BG, \"axes.labelcolor\": INK, \"text.color\": INK},\n)\n\n# Create figure (square for symmetric diagram)\nfig, ax = plt.subplots(figsize=(12, 12), facecolor=PAGE_BG)\n\n# Circle positions (equilateral triangle arrangement)\nr = 1.5  # Circle radius\ncenter_offset = 0.9  # Distance from center\n\n# Calculate centers for three overlapping circles\ncenters = [\n    (0, center_offset),  # Top (A - AWS)\n    (-center_offset * np.cos(np.pi / 6), -center_offset * np.sin(np.pi / 6)),  # Bottom-left (B - Google Cloud)\n    (center_offset * np.cos(np.pi / 6), -center_offset * np.sin(np.pi / 6)),  # Bottom-right (C - Azure)\n]\n\n# Draw circles with transparency using Okabe-Ito colors\ncircles = []\nfor center, color, label in zip(centers, IMPRINT, set_labels, strict=True):\n    circle = mpatches.Circle(center, r, alpha=0.4, facecolor=color, edgecolor=color, linewidth=3, label=label)\n    ax.add_patch(circle)\n    circles.append(circle)\n\n# Position labels outside circles\nlabel_offset = 2.3\nlabel_positions = [\n    (0, label_offset),  # Top\n    (-label_offset * np.cos(np.pi / 6) - 0.3, -label_offset * np.sin(np.pi / 6) - 0.3),  # Bottom-left\n    (label_offset * np.cos(np.pi / 6) + 0.3, -label_offset * np.sin(np.pi / 6) - 0.3),  # Bottom-right\n]\n\nfor pos, label, size in zip(label_positions, set_labels, set_sizes, strict=True):\n    ax.text(pos[0], pos[1], f\"{label}\\n(n={size})\", ha=\"center\", va=\"center\", fontsize=22, fontweight=\"bold\", color=INK)\n\n# Add counts to each region\n# Region positions (approximate centers of each region)\nregion_positions = {\n    \"A\": (0, 1.3),  # Only AWS\n    \"B\": (-1.2, -0.8),  # Only Google Cloud\n    \"C\": (1.2, -0.8),  # Only Azure\n    \"AB\": (-0.55, 0.3),  # AWS & Google Cloud\n    \"AC\": (0.55, 0.3),  # AWS & Azure\n    \"BC\": (0, -0.7),  # Google Cloud & Azure\n    \"ABC\": (0, 0),  # All three\n}\n\nregion_counts = {\"A\": only_a, \"B\": only_b, \"C\": only_c, \"AB\": ab_only, \"AC\": ac_only, \"BC\": bc_only, \"ABC\": abc}\n\nfor region, pos in region_positions.items():\n    count = region_counts[region]\n    pct = count / total_orgs * 100\n    ax.text(\n        pos[0],\n        pos[1],\n        f\"{count}\\n({pct:.0f}%)\",\n        ha=\"center\",\n        va=\"center\",\n        fontsize=20,\n        fontweight=\"bold\",\n        color=INK,\n        bbox={\"boxstyle\": \"round,pad=0.3\", \"facecolor\": ELEVATED_BG, \"edgecolor\": INK_SOFT, \"alpha\": 0.8},\n    )\n\n# Set axis properties - tighter bounds for better canvas utilization\nax.set_xlim(-3.0, 3.0)\nax.set_ylim(-2.8, 3.0)\nax.set_aspect(\"equal\")\nax.axis(\"off\")\n\n# Title\nax.set_title(\"venn-basic · seaborn · anyplot.ai\", fontsize=24, fontweight=\"bold\", pad=20, color=INK)\n\n# Add subtitle annotation explaining data context\nfig.text(\n    0.5,\n    0.02,\n    f\"Cloud Platform Adoption: {total_orgs} organizations surveyed\",\n    ha=\"center\",\n    va=\"bottom\",\n    fontsize=14,\n    style=\"italic\",\n    color=INK_SOFT,\n)\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}