简单地说,使用networkx作图,然后从matplotilb的canvas里面提取ndarray输出。
从邻接矩阵生成networkx中graph类,使用from_numpy_matrix
函数,详见:https://networkx.github.io/documentation/networkx-1.7/reference/generated/networkx.convert.from_numpy_matrix.html
使用networkx作图的介绍详见官网:https://networkx.github.io/documentation/stable/reference/introduction.html#drawing
为了使得生成的graph图片对节点编号不敏感,使用特定的layout,详见:https://networkx.github.io/documentation/stable/reference/drawing.html#module-networkx.drawing.layout
从而使用networkx从邻接矩阵中画图的样例代码如下:
G = nx