summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDouglas K. G. Araujo <dkg.araujo@gmail.com>2022-10-26 06:33:57 +0200
committerGitHub <noreply@github.com>2022-10-26 00:33:57 -0400
commit5d41b683f3bcdfaec25e8cef94a4e8ea585266da (patch)
treebfb6d0f762e9dcc14d790e724ed755e014f25e65 /examples
parent5209431693edf534a9b1c83ef0b3e72b182a3feb (diff)
downloadnetworkx-5d41b683f3bcdfaec25e8cef94a4e8ea585266da.tar.gz
Circular center node layout (#6114)
* center_node positioned according to param center * code formatting * Reverted to files in main * Adds example of custom node position * fixes spaces in layout.py * Update examples/drawing/plot_center_node.py Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> * clearer comment on custom node position Co-authored-by: Ross Barnowski <rossbar@berkeley.edu> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
Diffstat (limited to 'examples')
-rw-r--r--examples/drawing/plot_center_node.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/drawing/plot_center_node.py b/examples/drawing/plot_center_node.py
new file mode 100644
index 00000000..d7eb4706
--- /dev/null
+++ b/examples/drawing/plot_center_node.py
@@ -0,0 +1,20 @@
+"""
+====================
+Custom Node Position
+====================
+
+Draw a graph with node(s) located at user-defined positions.
+
+When a position is set by the user, the other nodes can still be neatly organised in a layout.
+"""
+
+import networkx as nx
+import numpy as np
+
+G = nx.path_graph(20) # An example graph
+center_node = 5 # Or any other node to be in the center
+edge_nodes = set(G) - {center_node}
+# Ensures the nodes around the circle are evenly distributed
+pos = nx.circular_layout(G.subgraph(edge_nodes))
+pos[center_node] = np.array([0, 0]) # manually specify node position
+nx.draw(G, pos, with_labels=True)