Sankey Diagram
Power Plant Energy Flow
Energy conversion flow from fuel input through power generation showing thermal losses and delivered electricity.
Output
Python
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib.path import Path
import numpy as np
def draw_flow(ax, x0, y0, x1, y1, w0, w1, color, alpha=0.6):
"""Draw smooth bezier flow between two points"""
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, tc='white'):
ax.add_patch(mpatches.FancyBboxPatch((x-w/2, y-h/2), w, h, boxstyle="round,pad=0.02",
fc=color, ec='white', lw=1.5))
ax.text(x, y, label, ha='center', va='center', fontsize=9, color=tc, fontweight='bold')
fig, ax = plt.subplots(figsize=(14, 8), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
s = 0.008 # scale
# Flows
draw_flow(ax, 0.5, 5, 2.5, 5, 1000*s, 1000*s, '#F54927', 0.7)
draw_flow(ax, 3.5, 5.8, 5.5, 7.5, 350*s, 350*s, '#C82909', 0.7)
draw_flow(ax, 3.5, 4.2, 5.5, 4, 650*s, 650*s, '#27D3F5', 0.7)
draw_flow(ax, 6.5, 3.5, 8.5, 2, 50*s, 50*s, '#9C2007', 0.7)
draw_flow(ax, 6.5, 4.3, 8.5, 5, 600*s, 600*s, '#6CF527', 0.7)
# Nodes
draw_node(ax, 0, 5, 0.6, 1000*s*1.3, '#F54927', 'Fuel\n1000 MW')
draw_node(ax, 3, 5, 0.6, 1000*s*1.3, '#F5B027', 'Power\nPlant')
draw_node(ax, 6, 7.5, 0.6, 350*s*1.5, '#C82909', 'Heat Loss\n350 MW')
draw_node(ax, 6, 4, 0.6, 650*s*1.3, '#27D3F5', 'Electricity\n650 MW')
draw_node(ax, 9, 2, 0.6, 50*s*3, '#9C2007', 'Trans Loss\n50 MW')
draw_node(ax, 9, 5, 0.6, 600*s*1.3, '#6CF527', 'Delivered\n600 MW')
ax.set_title('Power Plant Energy Flow Analysis', fontsize=16, color='white', fontweight='bold', pad=20)
ax.set_xlim(-1, 10)
ax.set_ylim(0, 10)
ax.axis('off')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Part-to-Whole
More Sankey Diagram examples
☕