summaryrefslogtreecommitdiff
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
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>
-rw-r--r--doc/release/release_dev.rst2
-rw-r--r--networkx/drawing/layout.py3
2 files changed, 4 insertions, 1 deletions
diff --git a/doc/release/release_dev.rst b/doc/release/release_dev.rst
index 6ebb3e1c..d11c0da3 100644
--- a/doc/release/release_dev.rst
+++ b/doc/release/release_dev.rst
@@ -185,6 +185,8 @@ API Changes
from ``communicability_betweeness_centrality``
- [`#4850 <https://github.com/networkx/networkx/pull/4850>`_]
Added ``dtype`` parameter to adjacency_matrix
+- [`#4867 <https://github.com/networkx/networkx/pull/4867>`_]
+ The function ``spring_layout`` now ignores 'fixed' nodes not in the graph
Deprecations
------------
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