I want to store in graphviz file a networkx object that has non-unique nodes. I have created non-unique nodes in networkx using labels. But it's just able to display the nodes with non-unique labels.
G = nx.MultiDiGraph()
G.add_node(0)
G.add_node(1)
G.add_node(2)
labels = {0: 'a', 1: 'b', 2: 'a'}
pos=nx.spring_layout(G)
nx.draw_networkx_nodes(G,pos)
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_labels(MG,pos,labels,font_size=16)
This gives return value of last statement and the output:
return value: {0: Text(-0.6135625730904766, -0.6074010681652476, 'a'),
1: Text(0.9319946933900001, -0.3925989318347525, 'b'),
2: Text(-0.31843212029952345, 1.0, 'a')}
Is there a way to take this output from draw_networkx_labels and use it to create graphviz file. I need non-unique nodes in graphviz file output. I'm trying to do something like below:
x = nx.draw_networkx_labels(G,pos,labels,font_size=16)
write_dot(x, "dot.gv")
s = Source.from_file('dot.gv')
s.view()
This will throw error as nx.draw_networkx_labels does not return the object it prints above. If I just use G object, it will not use labels 'a' and 'b'. Also, is there a simpler way to create non-unique nodes in networkx?