Sankey Diagram

Supply Chain Logistics

Product distribution flow from suppliers through warehouses to retail and e-commerce channels.

Output
Supply Chain Logistics
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.004

# Suppliers to warehouse
draw_flow(ax, 0.5, 7, 2.5, 5.5, 500*s, 500*s, '#F5B027', 0.7)
draw_flow(ax, 0.5, 4, 2.5, 4.5, 300*s, 300*s, '#F5D327', 0.7)
draw_flow(ax, 0.5, 2, 2.5, 3.5, 200*s, 200*s, '#D3F527', 0.7)

# Warehouse to channels
draw_flow(ax, 3.5, 5, 5.5, 7, 400*s, 400*s, '#27D3F5', 0.7)
draw_flow(ax, 3.5, 4.5, 5.5, 4, 350*s, 350*s, '#6CF527', 0.7)
draw_flow(ax, 3.5, 4, 5.5, 2, 200*s, 200*s, '#27F5B0', 0.7)
draw_flow(ax, 3.5, 4.2, 5.5, 0.5, 50*s, 50*s, '#C82909', 0.7)

# Nodes
draw_node(ax, 0, 7, 0.6, 500*s*1.4, '#F5B027', 'Supplier A\n500K')
draw_node(ax, 0, 4, 0.6, 300*s*1.6, '#F5D327', 'Supplier B\n300K')
draw_node(ax, 0, 2, 0.6, 200*s*2, '#D3F527', 'Supplier C\n200K')
draw_node(ax, 3, 5, 0.6, 1000*s*1.1, '#4927F5', 'Warehouse\n1M')
draw_node(ax, 6, 7, 0.6, 400*s*1.5, '#27D3F5', 'Retail\n400K')
draw_node(ax, 6, 4, 0.6, 350*s*1.5, '#6CF527', 'E-comm\n350K')
draw_node(ax, 6, 2, 0.6, 200*s*2, '#27F5B0', 'Wholesale\n200K')
draw_node(ax, 6, 0.5, 0.6, 50*s*4, '#C82909', 'Damaged\n50K')

ax.set_title('Supply Chain Distribution Flow', fontsize=16, color='white', fontweight='bold', pad=20)
ax.set_xlim(-1, 7)
ax.set_ylim(-0.5, 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