networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersBackRef
add_nodes_from(self, nodes_for_adding, **attr)

Parameters

nodes_for_adding : iterable container

A container of nodes (list, dict, set, etc.). OR A container of (node, attribute dict) tuples. Node attributes are updated using the attribute dict.

attr : keyword arguments, optional (default= no attributes)

Update attributes for all nodes in nodes. Node attributes specified in nodes as a tuple take precedence over attributes specified via keyword arguments.

Add multiple nodes.

See Also

add_node

Examples

>>> G = nx.Graph()  # or DiGraph, MultiGraph, MultiDiGraph, etc
... G.add_nodes_from("Hello")
... K3 = nx.Graph([(0, 1), (1, 2), (2, 0)])
... G.add_nodes_from(K3)
... sorted(G.nodes(), key=str) [0, 1, 2, 'H', 'e', 'l', 'o']

Use keywords to update specific node attributes for every node.

>>> G.add_nodes_from([1, 2], size=10)
... G.add_nodes_from([3, 4], weight=0.4)

Use (node, attrdict) tuples to update attributes for specific nodes.

>>> G.add_nodes_from([(1, dict(size=11)), (2, {"color": "blue"})])
... G.nodes[1]["size"] 11
>>> H = nx.Graph()
... H.add_nodes_from(G.nodes(data=True))
... H.nodes[1]["size"] 11
See :

Back References

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

networkx.classes.digraph.DiGraph.add_node networkx.classes.digraph.DiGraph networkx.algorithms.dag.transitive_reduction

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#436
type: <class 'function'>
Commit: