Sankey Diagram
Research Grant Distribution
Research funding flow from grant agencies through institutions to research disciplines.
Output
Python
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.path import Path
def draw_flow(ax, x0, y0, x1, y1, w0, w1, color, alpha=0.6):
cx = (x0 + x1) / 2
verts = [
(x0, y0 + w0/2), (cx, y0 + w0/2), (cx, y1 + w1/2), (x1, y1 + w1/2),
(x1, y1 - w1/2), (cx, y1 - w1/2), (cx, y0 - w0/2), (x0, y0 - w0/2),
(x0, y0 + w0/2)
]
codes = [Path.MOVETO] + [Path.CURVE4]*3 + [Path.LINETO] + [Path.CURVE4]*3 + [Path.CLOSEPOLY]
ax.add_patch(mpatches.PathPatch(Path(verts, codes), fc=color, alpha=alpha, ec='none'))
def draw_node(ax, x, y, w, h, color, label):
ax.add_patch(mpatches.FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle="round,pad=0.02",
fc=color, ec='#374151', lw=1.5))
ax.text(x, y, label, ha='center', va='center', fontsize=8, color='white', fontweight='bold')
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
s = 0.0008
# Agencies to total
draw_flow(ax, 0.5, 7, 2.5, 5.5, 3000*s, 3000*s, '#27D3F5', 0.6)
draw_flow(ax, 0.5, 4, 2.5, 4.5, 2000*s, 2000*s, '#276CF5', 0.6)
draw_flow(ax, 0.5, 2, 2.5, 3.5, 1000*s, 1000*s, '#4927F5', 0.6)
# Total to disciplines
draw_flow(ax, 3.5, 5.5, 5.5, 7.5, 2500*s, 2500*s, '#6CF527', 0.6)
draw_flow(ax, 3.5, 4.5, 5.5, 4.5, 2000*s, 2000*s, '#F5B027', 0.6)
draw_flow(ax, 3.5, 4, 5.5, 2, 1500*s, 1500*s, '#F5276C', 0.6)
# Nodes
draw_node(ax, 0, 7, 0.6, 3000*s*1.3, '#27D3F5', 'Federal\n$3B')
draw_node(ax, 0, 4, 0.6, 2000*s*1.5, '#276CF5', 'Private\n$2B')
draw_node(ax, 0, 2, 0.6, 1000*s*2, '#4927F5', 'State\n$1B')
draw_node(ax, 3, 5, 0.6, 6000*s*1.1, '#F54927', 'Total\n$6B')
draw_node(ax, 6, 7.5, 0.6, 2500*s*1.3, '#6CF527', 'Life Sci\n$2.5B')
draw_node(ax, 6, 4.5, 0.6, 2000*s*1.4, '#F5B027', 'Physical\n$2B')
draw_node(ax, 6, 2, 0.6, 1500*s*1.6, '#F5276C', 'Engineering\n$1.5B')
ax.set_title('Research Grant Distribution Flow', fontsize=16, color='#1f2937', fontweight='bold', pad=20)
ax.set_xlim(-1, 7)
ax.set_ylim(0, 9)
ax.axis('off')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Part-to-Whole
More Sankey Diagram examples
☕