{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Random Geometric Graph\n\nExample\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport networkx as nx\n\n# Use seed when creating the graph for reproducibility\nG = nx.random_geometric_graph(200, 0.125, seed=896803)\n# position is stored as node attribute data for random_geometric_graph\npos = nx.get_node_attributes(G, \"pos\")\n\n# find node near center (0.5,0.5)\ndmin = 1\nncenter = 0\nfor n in pos:\n    x, y = pos[n]\n    d = (x - 0.5) ** 2 + (y - 0.5) ** 2\n    if d < dmin:\n        ncenter = n\n        dmin = d\n\n# color by path length from node near center\np = dict(nx.single_source_shortest_path_length(G, ncenter))\n\nplt.figure(figsize=(8, 8))\nnx.draw_networkx_edges(G, pos, alpha=0.4)\nnx.draw_networkx_nodes(\n    G,\n    pos,\n    nodelist=list(p.keys()),\n    node_size=80,\n    node_color=list(p.values()),\n    cmap=plt.cm.Reds_r,\n)\n\nplt.xlim(-0.05, 1.05)\nplt.ylim(-0.05, 1.05)\nplt.axis(\"off\")\nplt.show()"
      ]
    }
  ],
  "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
}