Python_NetWorkX_教程
NetworkX
import networkx as nx
一、创建空的图
1.G = nx.Graph() #创建无向图
2.G = nx.Digraph() #创建有向图
二、添加节点
Node
、edge
、weighted_edge
-
Graph.__init__(**attr[, data]) Initialize a graph with edges, name, graph attributes.
-
Graph.add_node(n, **attr[, attr_dict]) Add a single node n and update node attributes.
-
Graph.add_nodes_from(nodes, **attr) Add multiple nodes.
-
Graph.remove_node(n) Remove node n.
-
Graph.remove_nodes_from(nodes) Remove multiple nodes.
-
Graph.add_edge(u, v, **attr[, attr_dict]) Add an edge between u and v.
-
Graph.add_edges_from(ebunch,**attr[,attr_dict])Add all the edges in ebunch.
-
Graph.add_weighted_edges_from(ebunch,**attr)Add all the edges in ebunch as weighted edges with specified weights.
-
Graph.remove_edge(u, v) Remove the edge between u and v.
-
Graph.remove_edges_from(ebunch) Remove all edges specified in ebunch.
-
Graph.add_star(nodes, **attr) Add a star.
-
Graph.add_path(nodes, **attr) Add a path.
-
Graph.add_cycle(nodes, **attr) Add a cycle.
-
Graph.clear() Remove all nodes and edges from the graph.
三、迭代节点
Node
、edge