{"spec_id":"network-bipartite","library":"matplotlib","language":"python","code":"\"\"\" anyplot.ai\nnetwork-bipartite: Bipartite Network Graph\nLibrary: matplotlib 3.10.9 | Python 3.13.13\nQuality: 86/100 | Created: 2026-05-14\n\"\"\"\n\nimport os\n\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib.lines import Line2D\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\"\nBRAND = \"#009E73\"  # Okabe-Ito pos 1 — researchers\nACCENT = \"#C475FD\"  # Okabe-Ito pos 2 — papers\n\n# Data — researcher-paper affiliation network (bibliometrics)\nnp.random.seed(42)\n\nresearchers = [\n    \"Chen, L.\",\n    \"Smith, A.\",\n    \"Patel, R.\",\n    \"Kim, J.\",\n    \"Müller, K.\",\n    \"Johnson, E.\",\n    \"Santos, M.\",\n    \"Tanaka, H.\",\n    \"Williams, P.\",\n    \"Okonkwo, F.\",\n    \"Larsson, B.\",\n    \"Ahmed, S.\",\n]\n\npapers = [\n    \"Deep Learning\",\n    \"NLP Survey\",\n    \"RL Methods\",\n    \"Vision Models\",\n    \"Graph Neural Nets\",\n    \"Transfer Learning\",\n    \"Attention Mech.\",\n    \"AutoML\",\n    \"Federated Learn.\",\n    \"Explainability\",\n    \"Causal Inference\",\n    \"Optimization\",\n    \"Generative AI\",\n    \"Robustness\",\n    \"Fairness in ML\",\n    \"Time Series ML\",\n    \"Recommenders\",\n    \"Multi-modal\",\n]\n\n# (researcher_idx, paper_idx)\nedges = [\n    (0, 0),\n    (0, 3),\n    (0, 6),\n    (0, 13),\n    (1, 1),\n    (1, 2),\n    (1, 9),\n    (2, 4),\n    (2, 5),\n    (2, 16),\n    (3, 0),\n    (3, 3),\n    (3, 7),\n    (3, 11),\n    (4, 5),\n    (4, 6),\n    (4, 8),\n    (4, 14),\n    (5, 1),\n    (5, 9),\n    (5, 10),\n    (5, 14),\n    (5, 15),\n    (6, 12),\n    (6, 16),\n    (6, 17),\n    (7, 2),\n    (7, 6),\n    (7, 7),\n    (7, 13),\n    (8, 2),\n    (8, 11),\n    (8, 15),\n    (9, 3),\n    (9, 12),\n    (9, 17),\n    (10, 4),\n    (10, 8),\n    (10, 15),\n    (11, 0),\n    (11, 1),\n    (11, 5),\n    (11, 10),\n]\n\nn_r, n_p = len(researchers), len(papers)\nr_degree = np.zeros(n_r, dtype=int)\np_degree = np.zeros(n_p, dtype=int)\nfor r, p in edges:\n    r_degree[r] += 1\n    p_degree[p] += 1\n\nr_y = np.linspace(0.90, 0.05, n_r)\np_y = np.linspace(0.90, 0.05, n_p)\nr_sizes = 160 + r_degree * 65\np_sizes = 160 + p_degree * 65\n\n# Plot\nfig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)\nax.set_facecolor(PAGE_BG)\n\n# Edges\nfor r, p in edges:\n    ax.plot([0.0, 1.0], [r_y[r], p_y[p]], color=INK_SOFT, alpha=0.18, linewidth=0.9, zorder=1)\n\n# Researcher nodes (circles)\nax.scatter([0.0] * n_r, r_y, s=r_sizes, c=BRAND, edgecolors=PAGE_BG, linewidth=1.5, zorder=3, alpha=0.90)\n\n# Paper nodes (squares)\nax.scatter([1.0] * n_p, p_y, s=p_sizes, c=ACCENT, marker=\"s\", edgecolors=PAGE_BG, linewidth=1.5, zorder=3, alpha=0.90)\n\n# Node labels\nfor i, name in enumerate(researchers):\n    ax.text(-0.04, r_y[i], name, ha=\"right\", va=\"center\", fontsize=14, color=INK_SOFT)\n\nfor i, name in enumerate(papers):\n    ax.text(1.04, p_y[i], name, ha=\"left\", va=\"center\", fontsize=14, color=INK_SOFT)\n\n# Column headers\nax.text(0.0, 0.96, \"Researchers\", ha=\"center\", va=\"bottom\", fontsize=18, fontweight=\"bold\", color=BRAND)\nax.text(1.0, 0.96, \"Papers\", ha=\"center\", va=\"bottom\", fontsize=18, fontweight=\"bold\", color=ACCENT)\n\n# Legend\nhandles = [\n    Line2D(\n        [0],\n        [0],\n        marker=\"o\",\n        linestyle=\"none\",\n        markerfacecolor=BRAND,\n        markersize=12,\n        label=\"Researcher (size = no. of papers)\",\n        markeredgecolor=PAGE_BG,\n    ),\n    Line2D(\n        [0],\n        [0],\n        marker=\"s\",\n        linestyle=\"none\",\n        markerfacecolor=ACCENT,\n        markersize=12,\n        label=\"Paper (size = no. of authors)\",\n        markeredgecolor=PAGE_BG,\n    ),\n    Line2D([0], [0], color=INK_SOFT, linewidth=2, alpha=0.6, label=\"Authorship link\"),\n]\nleg = ax.legend(handles=handles, loc=\"lower center\", ncol=3, fontsize=14, frameon=True, bbox_to_anchor=(0.5, -0.02))\nleg.get_frame().set_facecolor(ELEVATED_BG)\nleg.get_frame().set_edgecolor(INK_SOFT)\nplt.setp(leg.get_texts(), color=INK_SOFT)\n\nax.set_title(\"network-bipartite · matplotlib · anyplot.ai\", fontsize=24, fontweight=\"medium\", color=INK, pad=15)\n\nax.set_xlim(-0.48, 1.48)\nax.set_ylim(-0.07, 1.06)\nax.axis(\"off\")\n\nplt.tight_layout()\nplt.savefig(f\"plot-{THEME}.png\", dpi=300, bbox_inches=\"tight\", facecolor=PAGE_BG)\n"}