簡體   English   中英

如何使用 pygraphviz for dot 連接記錄中的 graphviz 節點?

[英]How can I connect graphviz nodes that are in records using pygraphviz for dot?

這是我在通過 pygraphviz 與 dot 接口時偶然發現的一個問題。 我正在通過標簽創建記錄,但我想知道如何連接記錄中的端口而不是記錄節點本身。

在 dot 它應該是這樣的:

a00 [shape = "record" label="{{RecordThing1}|{<1>A|<2>B|<3>C|<4>D|<5>E|<6>F}}"];
a01 [shape = "record" label="{{RecordThing2}|{<1>A|<2>B|<3>C|<4>D|<5>E|<6>F}}"];
a00:1 -> a01:1

找到解決辦法:可以使用edges的headporttailport屬性。 例如

agraph.add_node('a00', 'a01', tailport=1, headport=1)

閱讀更多信息:例如https://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:headport

tortal貼出的解決方案的代碼有一個小錯誤:需要使用add_edge(而不是add_node)。

假設兩個結構體 'a00' 和 'a01' 具有字段 'f0'、'f1' 和 'f2','tailport' 和 'headport' 邊緣屬性確實可以用於鏈接不同的字段

例如,用於將 a00:f1 與 a01:f0 鏈接

from pygraphviz import AGraph
g = AGraph()
g.add_node("a00", label="<f0> text | {<f1> text | <f2> text}", shape="record")
g.add_node("a01", label="<f0> text | {<f1> text | <f2> text}", shape="record")
g.add_edge('a00', 'a01', tailport='f1', headport='f0')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM