重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
sankey-diagram-creator by dkyazzentwatwa/chatgpt-skills
npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill sankey-diagram-creator创建交互式 Sankey 图,用于可视化类别之间的流程、转移和关系。非常适合预算流向、能源转移、用户旅程和数据管道。
from scripts.sankey_creator import SankeyCreator
# 从字典创建
sankey = SankeyCreator()
sankey.from_dict({
'source': ['A', 'A', 'B', 'B'],
'target': ['C', 'D', 'C', 'D'],
'value': [10, 20, 15, 25]
})
sankey.generate().save_html("flow.html")
# 从 CSV 创建
sankey = SankeyCreator()
sankey.from_csv("flows.csv", source="from", target="to", value="amount")
sankey.title("Budget Flow").generate().save_html("budget.html")
sankey = SankeyCreator()
# 从字典创建
sankey.from_dict({
'source': ['A', 'A', 'B'],
'target': ['X', 'Y', 'X'],
'value': [10, 20, 15]
})
# 从 CSV 文件创建
sankey.from_csv(
filepath="data.csv",
source="source_col",
target="target_col",
value="value_col",
label=None # 可选:链接标签列
)
# 从 pandas DataFrame 创建
import pandas as pd
df = pd.DataFrame({
'from': ['A', 'B'],
'to': ['C', 'C'],
'amount': [100, 200]
})
sankey.from_dataframe(df, source="from", target="to", value="amount")
# 添加单个流程
sankey.add_flow("Source", "Target", 50)
sankey.add_flow("Source", "Other", 30, label="30 units")
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
所有方法都返回 self 以支持链式调用。
# 节点颜色
sankey.node_colors({
'Income': '#2ecc71',
'Expenses': '#e74c3c',
'Savings': '#3498db'
})
# 使用配色方案自动分配颜色
sankey.node_colors(colormap='Pastel1')
# 链接颜色(按源节点、目标节点或自定义)
sankey.link_colors(by='source') # 按源节点着色
sankey.link_colors(by='target') # 按目标节点着色
sankey.link_colors(opacity=0.6) # 设置链接透明度
# 自定义链接颜色
sankey.link_colors(colors={
('Income', 'Expenses'): '#ff6b6b',
('Income', 'Savings'): '#4ecdc4'
})
# 标题
sankey.title("My Flow Diagram")
sankey.title("Budget Overview", font_size=20)
# 布局
sankey.layout(orientation='h') # 水平布局(默认)
sankey.layout(orientation='v') # 垂直布局
sankey.layout(pad=20) # 节点间距
# 生成图表
sankey.generate()
# 保存为交互式 HTML
sankey.save_html("diagram.html")
sankey.save_html("diagram.html", auto_open=True) # 在浏览器中打开
# 保存为静态图片
sankey.save_image("diagram.png")
sankey.save_image("diagram.svg", format='svg')
sankey.save_image("diagram.png", width=1200, height=800)
# 获取 Plotly 图形对象以进行自定义
fig = sankey.get_figure()
fig.update_layout(...)
# 在笔记本/浏览器中显示
sankey.show()
source,target,value,label
Income,Housing,1500,Rent
Income,Food,600,Groceries
Income,Transport,400,Car
Income,Savings,500,Emergency Fund
Savings,Investments,300,Stocks
data = {
'source': ['Income', 'Income', 'Income', 'Expenses'],
'target': ['Rent', 'Food', 'Savings', 'Tax'],
'value': [1500, 600, 500, 400],
'label': ['Housing', 'Groceries', 'Emergency', 'Federal'] # 可选
}
import pandas as pd
df = pd.DataFrame({
'from_node': ['A', 'A', 'B', 'C'],
'to_node': ['B', 'C', 'D', 'D'],
'flow_value': [100, 200, 150, 180]
})
| 名称 | 描述 |
|---|---|
Pastel1 | 柔和的粉彩色 |
Pastel2 | 柔和的淡彩色 |
Set1 | 鲜明的对比色 |
Set2 | 柔和的对比色 |
Set3 | 明亮的对比色 |
Paired | 配对配色方案 |
viridis | 蓝-绿-黄渐变 |
plasma | 紫-橙-黄渐变 |
# 十六进制颜色
sankey.node_colors({
'Category A': '#1abc9c',
'Category B': '#3498db',
'Category C': '#9b59b6'
})
# 命名颜色
sankey.node_colors({
'Revenue': 'green',
'Costs': 'red',
'Profit': 'blue'
})
# 基本用法
python sankey_creator.py --input flows.csv \
--source from --target to --value amount \
--output flow.html
# 带标题和颜色
python sankey_creator.py --input budget.csv \
--source category --target subcategory --value amount \
--title "Budget Breakdown" \
--colormap Pastel1 \
--output budget.html
# PNG 输出
python sankey_creator.py --input data.csv \
--source src --target dst --value val \
--output diagram.png \
--width 1200 --height 800
| 参数 | 描述 | 默认值 |
|---|---|---|
--input | 输入 CSV 文件 | 必需 |
--source | 源列名称 | 必需 |
--target | 目标列名称 | 必需 |
--value | 值列名称 | 必需 |
--output | 输出文件路径 | sankey.html |
--title | 图表标题 | None |
--colormap | 配色方案 | Pastel1 |
--link-opacity | 链接透明度 (0-1) | 0.5 |
--orientation | 'h' 或 'v' | h |
--width | 图片宽度 (PNG/SVG) | 1000 |
--height | 图片高度 (PNG/SVG) | 600 |
sankey = SankeyCreator()
sankey.from_dict({
'source': ['Salary', 'Salary', 'Salary', 'Salary', 'Savings', 'Investments'],
'target': ['Housing', 'Food', 'Transport', 'Savings', 'Investments', 'Stocks'],
'value': [2000, 800, 500, 1000, 700, 700]
})
sankey.title("Monthly Budget Flow")
sankey.node_colors({
'Salary': '#27ae60',
'Housing': '#e74c3c',
'Food': '#f39c12',
'Transport': '#3498db',
'Savings': '#9b59b6',
'Investments': '#1abc9c',
'Stocks': '#34495e'
})
sankey.generate().save_html("budget_flow.html")
sankey = SankeyCreator()
sankey.add_flow("Coal", "Electricity", 100)
sankey.add_flow("Gas", "Electricity", 80)
sankey.add_flow("Solar", "Electricity", 30)
sankey.add_flow("Electricity", "Industry", 120)
sankey.add_flow("Electricity", "Residential", 60)
sankey.add_flow("Electricity", "Commercial", 30)
sankey.title("Energy Flow")
sankey.node_colors(colormap='Set2')
sankey.link_colors(by='source', opacity=0.4)
sankey.generate().save_html("energy.html")
sankey = SankeyCreator()
sankey.from_dict({
'source': ['Landing', 'Landing', 'Product', 'Product', 'Cart', 'Cart'],
'target': ['Product', 'Exit', 'Cart', 'Exit', 'Checkout', 'Exit'],
'value': [1000, 200, 600, 200, 400, 100]
})
sankey.title("User Journey")
sankey.node_colors({
'Landing': '#3498db',
'Product': '#2ecc71',
'Cart': '#f1c40f',
'Checkout': '#27ae60',
'Exit': '#e74c3c'
})
sankey.generate().save_html("journey.html")
# 三级层次结构
data = {
'source': [
# 第一级 -> 第二级
'Revenue', 'Revenue', 'Revenue',
# 第二级 -> 第三级
'Products', 'Products', 'Services', 'Services'
],
'target': [
'Products', 'Services', 'Other',
'Electronics', 'Software', 'Consulting', 'Support'
],
'value': [500, 300, 50, 300, 200, 200, 100]
}
sankey = SankeyCreator()
sankey.from_dict(data)
sankey.title("Revenue Breakdown")
sankey.generate().save_html("revenue.html")
plotly>=5.15.0
pandas>=2.0.0
kaleido>=0.2.0
kaleido 包每周安装次数
37
代码仓库
GitHub 星标数
23
首次出现
Jan 24, 2026
安全审计
已安装于
opencode28
claude-code28
gemini-cli28
codex26
cursor26
github-copilot24
Create interactive Sankey diagrams to visualize flows, transfers, and relationships between categories. Perfect for budget flows, energy transfers, user journeys, and data pipelines.
from scripts.sankey_creator import SankeyCreator
# From dictionary
sankey = SankeyCreator()
sankey.from_dict({
'source': ['A', 'A', 'B', 'B'],
'target': ['C', 'D', 'C', 'D'],
'value': [10, 20, 15, 25]
})
sankey.generate().save_html("flow.html")
# From CSV
sankey = SankeyCreator()
sankey.from_csv("flows.csv", source="from", target="to", value="amount")
sankey.title("Budget Flow").generate().save_html("budget.html")
sankey = SankeyCreator()
# From dictionary
sankey.from_dict({
'source': ['A', 'A', 'B'],
'target': ['X', 'Y', 'X'],
'value': [10, 20, 15]
})
# From CSV file
sankey.from_csv(
filepath="data.csv",
source="source_col",
target="target_col",
value="value_col",
label=None # Optional: column for link labels
)
# From pandas DataFrame
import pandas as pd
df = pd.DataFrame({
'from': ['A', 'B'],
'to': ['C', 'C'],
'amount': [100, 200]
})
sankey.from_dataframe(df, source="from", target="to", value="amount")
# Add individual flows
sankey.add_flow("Source", "Target", 50)
sankey.add_flow("Source", "Other", 30, label="30 units")
All methods return self for chaining.
# Node colors
sankey.node_colors({
'Income': '#2ecc71',
'Expenses': '#e74c3c',
'Savings': '#3498db'
})
# Use colormap for automatic colors
sankey.node_colors(colormap='Pastel1')
# Link colors (by source, target, or custom)
sankey.link_colors(by='source') # Color by source node
sankey.link_colors(by='target') # Color by target node
sankey.link_colors(opacity=0.6) # Set link opacity
# Custom link colors
sankey.link_colors(colors={
('Income', 'Expenses'): '#ff6b6b',
('Income', 'Savings'): '#4ecdc4'
})
# Title
sankey.title("My Flow Diagram")
sankey.title("Budget Overview", font_size=20)
# Layout
sankey.layout(orientation='h') # Horizontal (default)
sankey.layout(orientation='v') # Vertical
sankey.layout(pad=20) # Node padding
# Generate the diagram
sankey.generate()
# Save as interactive HTML
sankey.save_html("diagram.html")
sankey.save_html("diagram.html", auto_open=True) # Open in browser
# Save as static image
sankey.save_image("diagram.png")
sankey.save_image("diagram.svg", format='svg')
sankey.save_image("diagram.png", width=1200, height=800)
# Get Plotly figure object for customization
fig = sankey.get_figure()
fig.update_layout(...)
# Show in notebook/browser
sankey.show()
source,target,value,label
Income,Housing,1500,Rent
Income,Food,600,Groceries
Income,Transport,400,Car
Income,Savings,500,Emergency Fund
Savings,Investments,300,Stocks
data = {
'source': ['Income', 'Income', 'Income', 'Expenses'],
'target': ['Rent', 'Food', 'Savings', 'Tax'],
'value': [1500, 600, 500, 400],
'label': ['Housing', 'Groceries', 'Emergency', 'Federal'] # Optional
}
import pandas as pd
df = pd.DataFrame({
'from_node': ['A', 'A', 'B', 'C'],
'to_node': ['B', 'C', 'D', 'D'],
'flow_value': [100, 200, 150, 180]
})
| Name | Description |
|---|---|
Pastel1 | Soft pastel colors |
Pastel2 | Muted pastels |
Set1 | Bold distinct colors |
Set2 | Muted distinct colors |
Set3 | Light distinct colors |
Paired | Paired color scheme |
# Hex colors
sankey.node_colors({
'Category A': '#1abc9c',
'Category B': '#3498db',
'Category C': '#9b59b6'
})
# Named colors
sankey.node_colors({
'Revenue': 'green',
'Costs': 'red',
'Profit': 'blue'
})
# Basic usage
python sankey_creator.py --input flows.csv \
--source from --target to --value amount \
--output flow.html
# With title and colors
python sankey_creator.py --input budget.csv \
--source category --target subcategory --value amount \
--title "Budget Breakdown" \
--colormap Pastel1 \
--output budget.html
# PNG output
python sankey_creator.py --input data.csv \
--source src --target dst --value val \
--output diagram.png \
--width 1200 --height 800
| Argument | Description | Default |
|---|---|---|
--input | Input CSV file | Required |
--source | Source column name | Required |
--target | Target column name | Required |
--value | Value column name | Required |
--output | Output file path |
sankey = SankeyCreator()
sankey.from_dict({
'source': ['Salary', 'Salary', 'Salary', 'Salary', 'Savings', 'Investments'],
'target': ['Housing', 'Food', 'Transport', 'Savings', 'Investments', 'Stocks'],
'value': [2000, 800, 500, 1000, 700, 700]
})
sankey.title("Monthly Budget Flow")
sankey.node_colors({
'Salary': '#27ae60',
'Housing': '#e74c3c',
'Food': '#f39c12',
'Transport': '#3498db',
'Savings': '#9b59b6',
'Investments': '#1abc9c',
'Stocks': '#34495e'
})
sankey.generate().save_html("budget_flow.html")
sankey = SankeyCreator()
sankey.add_flow("Coal", "Electricity", 100)
sankey.add_flow("Gas", "Electricity", 80)
sankey.add_flow("Solar", "Electricity", 30)
sankey.add_flow("Electricity", "Industry", 120)
sankey.add_flow("Electricity", "Residential", 60)
sankey.add_flow("Electricity", "Commercial", 30)
sankey.title("Energy Flow")
sankey.node_colors(colormap='Set2')
sankey.link_colors(by='source', opacity=0.4)
sankey.generate().save_html("energy.html")
sankey = SankeyCreator()
sankey.from_dict({
'source': ['Landing', 'Landing', 'Product', 'Product', 'Cart', 'Cart'],
'target': ['Product', 'Exit', 'Cart', 'Exit', 'Checkout', 'Exit'],
'value': [1000, 200, 600, 200, 400, 100]
})
sankey.title("User Journey")
sankey.node_colors({
'Landing': '#3498db',
'Product': '#2ecc71',
'Cart': '#f1c40f',
'Checkout': '#27ae60',
'Exit': '#e74c3c'
})
sankey.generate().save_html("journey.html")
# Three-level hierarchy
data = {
'source': [
# Level 1 -> Level 2
'Revenue', 'Revenue', 'Revenue',
# Level 2 -> Level 3
'Products', 'Products', 'Services', 'Services'
],
'target': [
'Products', 'Services', 'Other',
'Electronics', 'Software', 'Consulting', 'Support'
],
'value': [500, 300, 50, 300, 200, 200, 100]
}
sankey = SankeyCreator()
sankey.from_dict(data)
sankey.title("Revenue Breakdown")
sankey.generate().save_html("revenue.html")
plotly>=5.15.0
pandas>=2.0.0
kaleido>=0.2.0
kaleido packageWeekly Installs
37
Repository
GitHub Stars
23
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode28
claude-code28
gemini-cli28
codex26
cursor26
github-copilot24
前端代码审计工具 - 自动化检测可访问性、性能、响应式设计、主题化与反模式
57,700 周安装
viridis| Blue-green-yellow |
plasma | Purple-orange-yellow |
sankey.html--title | Diagram title | None |
--colormap | Color scheme | Pastel1 |
--link-opacity | Link opacity (0-1) | 0.5 |
--orientation | 'h' or 'v' | h |
--width | Image width (PNG/SVG) | 1000 |
--height | Image height (PNG/SVG) | 600 |