networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
add_edge(self, u_for_edge, v_for_edge, key=None, **attr)

The nodes u and v will be automatically added if they are not already in the graph.

Edge attributes can be specified with keywords or by directly accessing the edge's attribute dictionary. See examples below.

Notes

To replace/update edge data, use the optional key argument to identify a unique edge. Otherwise a new edge will be created.

NetworkX algorithms designed for weighted graphs cannot use multigraphs directly because it is not clear how to handle multiedge weights. Convert to Graph using edge attribute 'weight' to enable weighted graph algorithms.

Default keys are generated using the method :None:None:`new_edge_key()`. This method can be overridden by subclassing the base class and providing a custom :None:None:`new_edge_key()` method.

Parameters

u_for_edge, v_for_edge : nodes

Nodes can be, for example, strings or numbers. Nodes must be hashable (and not None) Python objects.

key : hashable identifier, optional (default=lowest unused integer)

Used to distinguish multiedges between a pair of nodes.

attr : keyword arguments, optional

Edge data (or labels or objects) can be assigned using keyword arguments.

Returns

The edge key assigned to the edge.

Add an edge between u and v.

See Also

add_edges_from

add a collection of edges

Examples

The following each add an additional edge e=(1, 2) to graph G:

>>> G = nx.MultiGraph()
... e = (1, 2)
... ekey = G.add_edge(1, 2) # explicit two-node form
... G.add_edge(*e) # single edge as tuple of two nodes 1
>>> G.add_edges_from([(1, 2)])  # add edges from iterable container
[2]

Associate data to edges using keywords:

>>> ekey = G.add_edge(1, 2, weight=3)
... ekey = G.add_edge(1, 2, key=0, weight=4) # update data for key=0
... ekey = G.add_edge(1, 3, weight=7, capacity=15, length=342.7)

For non-string attribute keys, use subscript notation.

>>> ekey = G.add_edge(1, 2)
... G[1][2][0].update({0: 5})
... G.edges[1, 2, 0].update({0: 5})
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.classes.multigraph.MultiGraph.has_edge networkx.classes.multigraph.MultiGraph.remove_edge networkx.classes.multigraph.MultiGraph.get_edge_data networkx.classes.multigraph.MultiGraph.add_edges_from networkx.classes.reportviews.EdgeView networkx.relabel.relabel_nodes networkx.classes.multigraph.MultiGraph networkx.convert.to_dict_of_dicts networkx.classes.multigraph.MultiGraph.add_edge networkx.classes.function.selfloop_edges networkx.classes.multigraph.MultiGraph.to_directed networkx.classes.multigraph.MultiGraph.to_undirected

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/classes/multigraph.py#416
type: <class 'function'>
Commit: