我正在尝试用Python生成鱼骨图(因果图或石川图)。有没有办法让它更像标准的鱼骨图?
from graphviz import Digraph
A=[('HW', 'Root'), ('SW', 'Root'),
('Electric', 'HW'), ('ink', 'HW'), ('windows', 'SW'), ('Drivers', 'SW'),
('Yellow', 'ink'), ('blue', 'ink'), ('pink', 'ink'),
('FE', 'Drivers'), ('BE', 'Drivers')]
e = Digraph()
e.attr(rankdir='LR')
for a in A:
e.node(a[0])
e.edge(a[0], a[1])
e.view()
2条答案
按热度按时间qoefvg9y1#
用graphviz做这样的事情真的很难,因为graphviz在如何安排事情上真的有自己的想法。你考虑过用matplotlib解决这个问题吗?matplotlib中有一个example creating a timeline,你可以用它作为基础,并根据需要进行修改。
gupuwyp22#
如上所述,鱼骨图超出了Graphviz的规范。下面是一个“相当不错”(旁观者的眼睛)的示例图版本。如果你觉得它可用,我会附上输入文件并解释发生了什么。如果不可用,请解释你需要什么。
问题:
neato -n
运行以创建可视文件运行上面的点,你会得到这个-不是很远,但不是一个鱼骨图:
现在,wishbone.gvpr-gvpr(https://www.graphviz.org/pdf/gvpr.1.pdf)程序将添加鱼骨耙:
gvpr程序调整X坐标
然后
neato -n
(https://graphviz.org/faq/#FaqDotWithNodeCoords)修复这些边。最后是命令行(Linux),它可以完成所有操作-(如果Windows不支持管道,只需将中间输出发送到临时文件)
赠送:
呼!