import plotly.graph_objects as go
fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 15,
thickness = 20,
line = dict(color = "black", width = 0.5),
label = ["A1", "A2", "B1", "B2", "C1", "C2"],
color = "green"
),
link = dict(
source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A1, B1, ...
target = [2, 3, 3, 4, 4, 5],
value = [7, 5, 3, 9, 5, 3]
))])
fig.update_layout(title_text="Simple Sankey Diagram using plotly in Python.", font_size=10)
fig.show()
http://pypi.python.org/pypi/Things
使用Things,显然您可以在Inkscape(一款免费的矢量编辑程序)中绘制基本形状,然后编写Python代码来缩放、旋转等等这些形状,以生成图像或动画。应该可以编写Python代码自动使Sankey箭头从其源点弹出,向上、向下或其他方向转向。http://www.sankey-diagrams.com/sankey-diagrams-are-directed-weighted-graphs/
http://www.svgopen.org/2003/papers/RenderingGraphs/index.html
我没有为您找到一个完整的解决方案,但我找到了一些部件,可能可以用于解决方案。祝你好运。其他答案提供了许多好的选项。然而,我想要一个能够与Matplotlib一起使用,但看起来更像sankeymatic图表的东西。
我发现了pySankey,但它只允许双射流的一级。
最终我编写了一个包SankeyFlow。它纯粹使用Matplotlib,并生成如下的流程。
from sankeyflow import Sankey
import matplotlib.pyplot as plt
plt.figure(figsize=(20, 10), dpi=144)
flows = [
('Product', 'Total revenue', 20779),
('Sevice\nand other', 'Total revenue', 30949),
('Total revenue', 'Gross margin', 34768),
('Total revenue', 'Cost of revenue', 16960),
('Gross margin', 'Operating income', 22247),
('Operating income', 'Income before\nincome taxes', 22247, {'flow_color_mode': 'dest'}),
('Other income, net', 'Income before\nincome taxes', 268),
('Gross margin', 'Research and\ndevelopment', 5758),
('Gross margin', 'Sales and marketing', 5379),
('Gross margin', 'General and\nadministrative', 1384),
('Income before\nincome taxes', 'Net income', 18765),
('Income before\nincome taxes', 'Provision for\nincome taxes', 3750),
]
s = Sankey(flows=flows, flow_color_mode='lesser')
s.draw()
plt.show()