其他分享
首页 > 其他分享> > networkx的学习笔记

networkx的学习笔记

作者:互联网

这两天由于要使用python画节点图,用到networkx,记录一下用法

//
	G = nx.Graph()//生成一个图,还可以生成有向图之类的,可查阅
    G.add_edges_from(edges2)//向图G中加入边集,edges2是一个list,形似:
    //edges2=[("as","sd"),("as","df")],as,sd,df就是三个节点,加入边集后自动生成节点,不需要再加入节点集
    pos = nx.spring_layout(G)#画出来的图不同主要是因为pos方法不同,该函数是用来生成G中每个节点的位置
    nx.draw(G,pos,with_labels=True, node_size=80,edge_color='orange',node_color='white')//draw函数还有许多其他参数,此处只是引入节点位置pos,生成标签表示节点,设置节点大小,设置边颜色,设置节点颜色
    plt.show()
//这是networkx为节点生成位置的一些函数,使用这些函数就能绘制出不同的图模型
import networkx as nx
circular_layout(G[, scale, center, dim]):Position nodes on a circle.
random_layout(G[, center, dim]):Position nodes uniformly at random in the unit square.
rescale_layout(pos[, scale]):Return scaled position array to (-scale, scale) in all axes.
shell_layout(G[, nlist, scale, center, dim]):Position nodes in concentric circles.
spring_layout(G[, k, pos, fixed, …]):Position nodes using Fruchterman-Reingold force-directed algorithm.
spectral_layout(G[, weight, scale, center, dim]):Position nodes using the eigenvectors of the graph Laplacian.

标签:scale,layout,pos,笔记,学习,networkx,Position,nodes,节点
来源: https://blog.csdn.net/luojio/article/details/121445339