Python Networkx graphviz:绘制节点的正确位置

时间:2016-03-01 18:25:41

标签: python graphviz networkx

我想使用Graphvize绘制以下图表:

xx = nx.DiGraph()

xx.add_node("P")
xx.add_node("C0")
xx.add_node("C1")
xx.add_node("I2")
xx.add_node("C3")
xx.add_node("C4")
xx.add_node("I5")
xx.add_node("C6")
xx.add_node("C7")

xx.node["C1"]['pos'] = (2,3)
xx.node["I2"]['pos'] = (4,5)
xx.node["C3"]['pos'] = (6,7)
xx.node["C4"]['pos'] = (6,5)
xx.node["I5"]['pos'] = (4,1)
xx.node["C6"]['pos'] = (6,2)
xx.node["C7"]['pos'] = (6,0)
xx.node["P"]['pos'] = (-2,3)
xx.node["C0"]['pos'] = (0,3)

xx.add_edge("P", "C0")
xx.add_edge("C0", "C1")
xx.add_edge("C1", "I2")
xx.add_edge("I2", "C3")
xx.add_edge("I2", "C4")
xx.add_edge("C1", "I5")
xx.add_edge("I5", "C6")
xx.add_edge("I5", "C7")

layout = dict((n, xx.node[n]["pos"]) for n in xx.nodes_iter())
nx.draw(xx,pos=layout,node_color='white')

nx.write_dot(xx,'66666.dot')

使用matplotlitb,我确定所有节点的正确位置:

enter image description here

Graphviz是一个没有位置的图形。

enter image description here

我的问题:是否有可能在Graphviz中添加正确的位置?是否可以打开文件" 66666.dot"直接在python?

非常感谢你的帮助!

0 个答案:

没有答案