I am using networkX to generate a tree structure as follows (I am following the answer of this question).
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
G.add_node("ROOT")
for i in range(5):
G.add_node("Child_%i" % i)
G.add_node("Grandchild_%i" % i)
G.add_node("Greatgrandchild_%i" % i)
G.add_edge("ROOT", "Child_%i" % i)
G.add_edge("Child_%i" % i, "Grandchild_%i" % i)
G.add_edge("Grandchild_%i" % i, "Greatgrandchild_%i" % i)
# write dot file to use with graphviz
# run "dot -Tpng test.dot >test.png"
nx.write_dot(G,'test.dot')
# same layout using matplotlib with no labels
plt.title('draw_networkx')
pos=nx.graphviz_layout(G, prog='dot')
nx.draw(G, pos, with_labels=False, arrows=False)
plt.savefig('nx_test.png')
I want to draw a tree as in the following figure.
However, I am getting an error saying AttributeError: module 'networkx' has no attribute 'write_dot'
. My networkx version is 1.11 (using conda). I tried different hacks, but none of them worked.
So, I am interested in knowing if there is another way of drawing tree structures using networkx to get an output similar to the one mentioned in the figure. Please let me know.