graphviz graphviz与2组节点垂直对齐

时间:2014-06-12 13:48:06

标签: python-2.7 graph vertical-alignment graphviz pygraphviz

我在python中使用graphviz。我尝试模拟能量流程图。所有商品(技术)都在矩形节点中。产生的所有燃料都是椭圆形的。 我想得到一个图表,给我一个更好的alinement,其中第一列应该是矩形,最后一列也应该是矩形。垂直的节奏应该是

  

矩形 - > Elipse - >矩形 - > Elipse - >矩形 - > Elipse - >   矩形 - > Elipse - >矩形(等)

我该怎么做?我已经检查了文档,但无法找到...

由于

#!/usr/bin/env python

import pygraphviz as pgv

A=pgv.AGraph(directed=True,strict=False,rankdir='LR')


#@@ 1 COPY ALL TECHNO SET

A.node_attr['shape']='rectangle' #all techno are rectangle 

A.add_node("E01")
A.add_node("E21")
A.add_node("E31")
A.add_node("E51")
A.add_node("E70")
A.add_node("IMPDSL1")
A.add_node("IMPGSL1")
A.add_node("IMPHCO1")
A.add_node("IMPOIL1")
A.add_node("IMPURN1")
A.add_node("RHE")
A.add_node("RHO")
A.add_node("RL1")
A.add_node("SRE")
A.add_node("TXD")
A.add_node("TXE")
A.add_node("TXG")
A.add_node("RIV")
A.add_node("RHu")
A.add_node("RLu")
A.add_node("TXu")

#@@ 2 COPY ALL FUEL SET

A.node_attr['shape']='ellipse' 

A.add_node("DSL")
A.add_node("ELC")
A.add_node("GSL")
A.add_node("HCO")
A.add_node("HYD")
A.add_node("OIL")
A.add_node("DSL")
A.add_node("OIL")
A.add_node("URN")
A.add_node("RH")
A.add_node("RL")
A.add_node("TX")



#@@ 3 COPY ALL OUTPUTACTIVITY

A.add_edge("E01" , "ELC")
A.add_edge("E21" , "ELC")
A.add_edge("E31" , "ELC")
A.add_edge("E51" , "ELC")
A.add_edge("E70" , "ELC")
A.add_edge("IMPDSL1" , "DSL")
A.add_edge("IMPGSL1" , "GSL")
A.add_edge("IMPHCO1" , "HCO")
A.add_edge("IMPOIL1" , "OIL")
A.add_edge("IMPURN1" , "URN")
A.add_edge("RHE" , "RH")
A.add_edge("RHO" , "RH")
A.add_edge("RL1" , "RL")
A.add_edge("SRE" , "DSL")
A.add_edge("SRE" , "GSL")
A.add_edge("TXD" , "TX")
A.add_edge("TXE" , "TX")
A.add_edge("TXG" , "TX")
A.add_edge("RIV" , "HYD")
A.add_edge("RHu" , "RH")
A.add_edge("RLu" , "RL")
A.add_edge("TXu" , "TX")


#@@ 3 COPY ALL INPUTACTIVITY

A.add_edge("DSL", "E70")
A.add_edge("DSL", "RHO")
A.add_edge("DSL", "TXD")
A.add_edge("ELC", "E51")
A.add_edge("ELC", "RHE")
A.add_edge("ELC", "RL1")
A.add_edge("ELC", "TXE")
A.add_edge("GSL", "TXG")
A.add_edge("HCO", "E01")
A.add_edge("HYD", "E31")
A.add_edge("OIL", "SRE")
A.add_edge("URN", "E21")

# adjust a graph parameter
A.graph_attr['epsilon']='0.001'


print A.string() 
A.layout('dot') # layout with dot
A.draw('foo.png') # write to file

enter image description here

1 个答案:

答案 0 :(得分:0)

您好我发现它与命令

完美配合
B=A.add_subgraph(["IMPOIL1","IMPDSL1","RIV", "IMPURN1", "IMPHCO1", "IMPGSL1"])

B.graph_attr['rank']='same'

希望它可以帮助将来的某个人。

由于