networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersBackRef
add_edge(self, u_of_edge, v_of_edge, **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

Adding an edge that already exists updates the edge data.

Many NetworkX algorithms designed for weighted graphs use an edge attribute (by default :None:None:`weight`) to hold a numerical value.

Parameters

u_of_edge, v_of_edge : nodes

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

attr : keyword arguments, optional

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

Add an edge between u and v.

See Also

add_edges_from

add a collection of edges

Examples

The following all add the edge e=(1, 2) to graph G:

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

Associate data to edges using keywords:

>>> G.add_edge(1, 2, weight=3)
... G.add_edge(1, 3, weight=7, capacity=15, length=342.7)

For non-string attribute keys, use subscript notation.

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

Back References

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

networkx.classes.digraph.DiGraph networkx.algorithms.assortativity.pairs.node_degree_xy networkx.algorithms.flow.edmondskarp.edmonds_karp networkx.algorithms.flow.mincost.min_cost_flow networkx.algorithms.flow.dinitz_alg.dinitz networkx.algorithms.tree.recognition.is_branching networkx.algorithms.flow.maxflow.minimum_cut_value networkx.algorithms.centrality.reaching.local_reaching_centrality networkx.classes.digraph.DiGraph.add_edges_from networkx.algorithms.components.weakly_connected.is_weakly_connected networkx.algorithms.flow.maxflow.maximum_flow networkx.algorithms.assortativity.pairs.node_attribute_xy networkx.algorithms.centrality.reaching.global_reaching_centrality networkx.algorithms.flow.maxflow.maximum_flow_value networkx.algorithms.tree.recognition.is_arborescence networkx.algorithms.flow.preflowpush.preflow_push networkx.classes.graph.Graph.number_of_edges networkx.classes.digraph.DiGraph.to_undirected networkx.classes.graph.Graph.to_directed networkx.algorithms.flow.networksimplex.network_simplex networkx.algorithms.flow.shortestaugmentingpath.shortest_augmenting_path networkx.classes.graphviews.reverse_view networkx.algorithms.flow.boykovkolmogorov.boykov_kolmogorov networkx.algorithms.flow.mincost.min_cost_flow_cost networkx.algorithms.flow.maxflow.minimum_cut networkx.classes.function.is_weighted networkx.algorithms.flow.capacityscaling.capacity_scaling

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/digraph.py#576
type: <class 'function'>
Commit: