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

39 Elements
networkx.classes.reportviews.EdgeDataView
networkx.algorithms.tree.mst.maximum_spanning_edges
networkx.classes.digraph.DiGraph
networkx.algorithms.assortativity.mixing.attribute_mixing_dict
networkx.algorithms.tree.mst.minimum_spanning_edges
networkx.algorithms.components.biconnected.biconnected_component_edges
networkx.classes.function.is_negatively_weighted
networkx.algorithms.summarization.snap_aggregation
networkx.algorithms.tree.mst.maximum_spanning_tree
networkx.classes.function.number_of_selfloops
networkx.algorithms.connectivity.stoerwagner.stoer_wagner
networkx.classes.graph.Graph.to_undirected
networkx.readwrite.edgelist.write_weighted_edgelist
networkx.linalg.attrmatrix.attr_matrix
networkx.classes.function.freeze
networkx.classes.graph.Graph
networkx.algorithms.isolate.is_isolate
networkx.linalg.attrmatrix.attr_sparse_matrix
networkx.classes.graph.Graph.add_edge
networkx.algorithms.components.biconnected.biconnected_components
networkx.classes.graph.Graph.add_edges_from
networkx.algorithms.tree.mst.minimum_spanning_tree
networkx.classes.function.nodes_with_selfloops
networkx.classes.graph.Graph.add_weighted_edges_from
networkx.classes.reportviews.EdgeView
networkx.convert_matrix.to_numpy_recarray
networkx.readwrite.edgelist.write_edgelist
networkx.algorithms.tree.recognition.is_tree
networkx.classes.reportviews.DiDegreeView
networkx.classes.graph.Graph.size
networkx.classes.graph.Graph.to_directed
networkx.algorithms.tree.recognition.is_forest
networkx.convert_matrix.to_numpy_array
networkx.classes.digraph.DiGraph.add_edge
networkx.algorithms.bipartite.projection.collaboration_weighted_projected_graph
networkx.classes.reportviews.DegreeView
networkx.algorithms.bipartite.edgelist.write_edgelist
networkx.algorithms.components.biconnected.articulation_points
networkx.algorithms.components.biconnected.is_biconnected

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