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_nodes_from networkx.algorithms.bipartite.edgelist.generate_edgelist networkx.algorithms.assortativity.mixing.attribute_mixing_dict networkx.algorithms.connectivity.edge_kcomponents.k_edge_subgraphs networkx.classes.graph.Graph.update networkx.classes.graph.Graph.add_nodes_from networkx.algorithms.connectivity.edge_augmentation.weighted_one_edge_augmentation networkx.algorithms.isomorphism.isomorph.is_isomorphic networkx.algorithms.connectivity.edge_kcomponents.k_edge_components networkx.classes.graph.Graph networkx.classes.reportviews.NodeView.data networkx.classes.function.get_node_attributes networkx.algorithms.bipartite.edgelist.read_edgelist networkx.algorithms.assortativity.correlation.numeric_assortativity_coefficient networkx.algorithms.assortativity.correlation.attribute_assortativity_coefficient networkx.generators.geometric.geometric_edges networkx.classes.multidigraph.MultiDiGraph networkx.classes.graph.Graph.add_node networkx.algorithms.bipartite.edgelist.write_edgelist networkx.classes.multigraph.MultiGraph networkx.algorithms.connectivity.edge_kcomponents.EdgeComponentAuxGraph networkx.algorithms.connectivity.edge_augmentation.unconstrained_one_edge_augmentation

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