importmatplotlib.pyplotaspltimportnetworkxasnxtry:importpygraphvizfromnetworkx.drawing.nx_agraphimportgraphviz_layoutexceptImportError:try:importpydotfromnetworkx.drawing.nx_pydotimportgraphviz_layoutexceptImportError:raiseImportError("This example needs Graphviz and either ""PyGraphviz or pydot")G=nx.balanced_tree(3,5)pos=graphviz_layout(G,prog='twopi',args='')plt.figure(figsize=(8,8))nx.draw(G,pos,node_size=20,alpha=0.5,node_color="blue",with_labels=False)plt.axis('equal')plt.show()