diff options
-rw-r--r-- | doc/release/release_dev.rst | 2 | ||||
-rw-r--r-- | networkx/drawing/layout.py | 3 |
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 |