python - Duplicate edges created in Pygraphviz -
i using pygraphviz generate hierarchical tree structure several levels , nodes. whenever try create edge between 2 nodes (i have unique index assigned every node in tree), pygraphviz generates 2 edges, considering both actual node value , index whereas expecting it, create edge between node unique indices. please @ example code , figure below.
sample code:
from pygraphviz import * word_link = [] = agraph(directed=true) ind = 0 a.add_node(ind, color='lightskyblue', style='filled', label='root', shape='box') sen_ind = ind + 1 # sentence 1 a.add_node(sen_ind, color='lightcoral', style='filled', label=0, shape='box') a.add_edge(ind, sen_ind, color='plum', style='filled') word_ind = sen_ind + 1 # word 1 a.add_node(word_ind, color='lightsalmon', style='filled', shape='box', label=0) word_link.append(word_ind) a.add_edge(sen_ind, word_ind, color='plum', style='filled') word_ind += 1 # word 2 a.add_node(word_ind, color='lightsalmon', style='filled', shape='box', label=1) a.add_edge(sen_ind, word_ind, color='plum', style='filled') sen_ind = word_ind + 1 # sentence 2 a.add_node(sen_ind, color='lightcoral', style='filled', label=1, shape='box') a.add_edge(ind, sen_ind, color='plum', style='filled') word_ind = sen_ind + 1 # word 1 a.add_node(word_ind, color='lightsalmon', style='filled', label=0, shape='box') a.add_edge(sen_ind, word_ind, color='plum', style='filled') word_ind += 1 # word 2 a.add_node(word_ind, color='lightsalmon', style='filled', label=1, shape='box') word_link.append(word_ind) a.add_edge(sen_ind, word_ind, color='plum', style='filled') # doesn't work | need fix a.add_edge(word_link[0], word_link[1], color='sienna', style='filled') a.layout() # layout default (neato) a.draw('simple.png',prog='dot') # draw png tree generated duplicate edges 
expected figure: 
try adding constraint=false:
a.add_edge(word_link[0], word_link[1], constraint=false, color='sienna', style='filled')
Comments
Post a Comment