Sankey Diagram

Carbon Emissions Flow

Global carbon emissions flow from source sectors to atmospheric contribution by region.

Output
Carbon Emissions Flow
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='white', 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='#0a0a0f')
ax.set_facecolor('#0a0a0f')

s = 0.12

# Sectors to total
draw_flow(ax, 0.5, 7.5, 2.5, 5.5, 15*s, 15*s, '#F54927', 0.7)
draw_flow(ax, 0.5, 5.5, 2.5, 4.8, 12*s, 12*s, '#C82909', 0.7)
draw_flow(ax, 0.5, 3.5, 2.5, 4.2, 10*s, 10*s, '#9C2007', 0.7)
draw_flow(ax, 0.5, 1.5, 2.5, 3.5, 8*s, 8*s, '#F5B027', 0.7)

# Nodes
draw_node(ax, 0, 7.5, 0.6, 15*s*1.3, '#F54927', 'Energy\n15 GT')
draw_node(ax, 0, 5.5, 0.6, 12*s*1.3, '#C82909', 'Transport\n12 GT')
draw_node(ax, 0, 3.5, 0.6, 10*s*1.4, '#9C2007', 'Industry\n10 GT')
draw_node(ax, 0, 1.5, 0.6, 8*s*1.5, '#F5B027', 'Buildings\n8 GT')
draw_node(ax, 3, 5, 0.6, 45*s*1.1, '#F5276C', 'Total CO2\n45 GT')

ax.set_title('Global Carbon Emissions by Sector', fontsize=16, color='white', fontweight='bold', pad=20)
ax.set_xlim(-1, 4)
ax.set_ylim(0, 9)
ax.axis('off')
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Part-to-Whole

Did this help you?

Support PyLucid to keep it free & growing

Support