summaryrefslogtreecommitdiff
path: root/networkx
diff options
context:
space:
mode:
authorDanylo Ulianych <dizcza@gmail.com>2021-06-06 20:24:23 +0300
committerGitHub <noreply@github.com>2021-06-06 13:24:23 -0400
commitb173f2bb323c798c979a2963e8a05d67c9c1f3d7 (patch)
treed6d71d84c2186ab2dab563ee48b6363c262e4998 /networkx
parentf5cb21f5408845944b373a49b176af3134504b00 (diff)
downloadnetworkx-b173f2bb323c798c979a2963e8a05d67c9c1f3d7.tar.gz
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 <dschult@colgate.edu>
Diffstat (limited to 'networkx')
-rw-r--r--networkx/drawing/layout.py3
1 files changed, 2 insertions, 1 deletions
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