From b173f2bb323c798c979a2963e8a05d67c9c1f3d7 Mon Sep 17 00:00:00 2001 From: Danylo Ulianych Date: Sun, 6 Jun 2021 20:24:23 +0300 Subject: spring_layout: ignore 'fixed' nodes not in the graph nodes (#4867) * spring_layout: ignore 'fixed' nodes not in the graph nodes * add api change to release notes Co-authored-by: Dan Schult --- networkx/drawing/layout.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'networkx') diff --git a/networkx/drawing/layout.py b/networkx/drawing/layout.py index b7637ece..558baff5 100644 --- a/networkx/drawing/layout.py +++ b/networkx/drawing/layout.py @@ -390,6 +390,7 @@ def spring_layout( fixed : list or None optional (default=None) Nodes to keep fixed at initial position. + Nodes not in ``G.nodes`` are ignored. ValueError raised if `fixed` specified and `pos` not. iterations : int optional (default=50) @@ -447,7 +448,7 @@ def spring_layout( if node not in pos: raise ValueError("nodes are fixed without positions given") nfixed = {node: i for i, node in enumerate(G)} - fixed = np.asarray([nfixed[node] for node in fixed]) + fixed = np.asarray([nfixed[node] for node in fixed if node in nfixed]) if pos is not None: # Determine size of existing domain to adjust initial positions -- cgit v1.2.1