{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Custom Node Position\n\nDraw a graph with node(s) located at user-defined positions.\n\nWhen a position is set by the user, the other nodes can still be neatly organised in a layout.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import networkx as nx\nimport numpy as np\n\nG = nx.path_graph(20) # An example graph\ncenter_node = 5 # Or any other node to be in the center\nedge_nodes = set(G) - {center_node}\n# Ensures the nodes around the circle are evenly distributed\npos = nx.circular_layout(G.subgraph(edge_nodes))\npos[center_node] = np.array([0, 0]) # manually specify node position\nnx.draw(G, pos, with_labels=True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Generated by dwww version 1.16 on Wed Apr 8 11:16:11 CEST 2026.