转换#

一个示例,展示如何使用 pygraphviz.AGraph 类接口在 graphviz 之间进行转换。

plot conversion
import networkx as nx

G = nx.complete_graph(5)
A = nx.nx_agraph.to_agraph(G)  # 转换为Graphviz图
X1 = nx.nx_agraph.from_agraph(A)  # 转换回 networkx(但作为 Graph)
X2 = nx.Graph(A)  # 一种花哨的转换方式
G1 = nx.Graph(X1)  # now make it a Graph

A.write("k5.dot")  # write to dot file
X3 = nx.nx_agraph.read_dot("k5.dot")  # read from dotfile

# 你也可以使用AGraph.draw方法直接创建.png文件
A.draw("k5.png", prog="neato")

Total running time of the script: (0 minutes 0.018 seconds)

Gallery generated by Sphinx-Gallery