An undirected graph that allows multiple (parallel) edges with arbitrary data on the edges.
Subclass of Graph.
An empty multigraph is created with
>>> G=nx.MultiGraph()
Examples
Create an empty graph structure (a “null graph”) with no nodes and no edges
>>> G=nx.MultiGraph()
You can add nodes in the same way as the simple Graph class >>> G.add_nodes_from(xrange(100,110))
You can add edges with data/labels/objects as for the Graph class, but here the same two nodes can have more than one edge between them.
>>> G.add_edges_from([(1,2,0.776),(1,2,0.535)])
See also the MultiDiGraph class for a directed graph version.
MultiGraph inherits from Graph, overriding the following methods:
MultiGraph.add_node (n) | Add a single node n. |
MultiGraph.add_nodes_from (nbunch) | Add nodes from nbunch. |
MultiGraph.remove_node (n) | Remove node n. |
MultiGraph.remove_nodes_from (nbunch) | Remove nodes specified in nbunch. |
MultiGraph.add_edge (u, v[, data]) | Add an edge between u and v with optional data. |
MultiGraph.add_edges_from (ebunch[, data]) | Add all the edges in ebunch. |
MultiGraph.remove_edge (u, v[, data]) | Remove the edge between (u,v). |
MultiGraph.remove_edges_from (ebunch) | Remove all edges specified in ebunch. |
MultiGraph.add_star (nlist[, data]) | Add a star. |
MultiGraph.add_path (nlist[, data]) | Add a path. |
MultiGraph.add_cycle (nlist[, data]) | Add a cycle. |
MultiGraph.clear () | Remove all nodes and edges. |
MultiGraph.nodes () | Return a list of the nodes. |
MultiGraph.nodes_iter () | Return an iterator for the nodes. |
MultiGraph.__iter__ () | Iterate over the nodes. Use “for n in G”. |
MultiGraph.edges ([nbunch, data]) | Return a list of edges. |
MultiGraph.edges_iter ([nbunch, data]) | Return an iterator over the edges. |
MultiGraph.get_edge (u, v[, no_edge]) | Return a list of edge data for all edges between u and v. |
MultiGraph.neighbors (n) | Return a list of the nodes connected to the node n. |
MultiGraph.neighbors_iter (n) | Return an iterator over all neighbors of node n. |
MultiGraph.__getitem__ (n) | Return the neighbors of node n. Use “G[n]”. |
MultiGraph.adjacency_list () | Return an adjacency list as a Python list of lists |
MultiGraph.adjacency_iter () | Return an iterator of (node, adjacency dict) tuples for all nodes. |
MultiGraph.nbunch_iter ([nbunch]) | Return an iterator of nodes contained in nbunch that are also in the graph. |
MultiGraph.has_node (n) | Return True if graph has node n. |
MultiGraph.__contains__ (n) | Return True if n is a node, False otherwise. Use “n in G”. |
MultiGraph.has_edge (u, v) | Return True if graph contains the edge (u,v), False otherwise. |
MultiGraph.has_neighbor (u, v) | Return True if node u has neighbor v. |
MultiGraph.nodes_with_selfloops () | Return a list of nodes with self loops. |
MultiGraph.selfloop_edges () | Return a list of selfloop edges with data (3-tuples). |
MultiGraph.order () | Return the number of nodes. |
MultiGraph.number_of_nodes () | Return the number of nodes. |
MultiGraph.__len__ () | Return the number of nodes. Use “len(G)”. |
MultiGraph.size ([weighted]) | Return the number of edges. |
MultiGraph.number_of_edges ([u, v]) | Return the number of edges between two nodes. |
MultiGraph.number_of_selfloops () | Return the number of selfloop edges counting multiple edges. |
MultiGraph.degree ([nbunch, with_labels, ...]) | Return the degree of a node or nodes. |
MultiGraph.degree_iter ([nbunch, weighted]) | Return an iterator for (node, degree). |
MultiGraph.copy () | Return a copy of the graph. |
MultiGraph.to_directed () | Return a directed representation of the graph. |
MultiGraph.subgraph (nbunch[, copy]) | Return the subgraph induced on nodes in nbunch. |