def create_image(g, path):
path = os.path.relpath(path)
if pygraphviz:
a = nx.nx_agraph.to_agraph(g)
# ['neato'|'dot'|'twopi'|'circo'|'fdp'|'nop']
a.layout(prog='neato', args="-Goverlap=false -Gsplines=true") # splines=true
a.draw(path)
elif plt:
nodes = g.nodes(True)
colors = [attrs['color'] for n, attrs in nodes]
labels = {n: attrs['label'] for n, attrs in nodes}
if graphviz_layout:
pos = graphviz_layout(g)
else:
pos = nx.spring_layout(g)
nx.draw_networkx_nodes(g, pos, node_shape='o', node_color=colors, alpha=0.3)
nx.draw_networkx_edges(g, pos, style='solid', alpha=0.2)
nx.draw_networkx_labels(g, pos, labels, alpha=0.5)
# plt.show()
plt.imsave(path) # todo: this is not tested!
print 'Image saved to', path
评论列表
文章目录