summaryrefslogtreecommitdiff
path: root/tutorial.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'tutorial.ipynb')
-rw-r--r--tutorial.ipynb156
1 files changed, 78 insertions, 78 deletions
diff --git a/tutorial.ipynb b/tutorial.ipynb
index ed98978d..35064095 100644
--- a/tutorial.ipynb
+++ b/tutorial.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "40fbf295",
+ "id": "faf90572",
"metadata": {},
"source": [
"## Tutorial\n",
@@ -17,7 +17,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "cef8525c",
+ "id": "509e60e1",
"metadata": {},
"outputs": [],
"source": [
@@ -27,7 +27,7 @@
},
{
"cell_type": "markdown",
- "id": "c89a63e1",
+ "id": "8f16129b",
"metadata": {},
"source": [
"By definition, a `Graph` is a collection of nodes (vertices) along with\n",
@@ -47,7 +47,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2d14bc17",
+ "id": "bd6562e0",
"metadata": {},
"outputs": [],
"source": [
@@ -56,7 +56,7 @@
},
{
"cell_type": "markdown",
- "id": "86d31597",
+ "id": "2d825f0d",
"metadata": {},
"source": [
"or add nodes from any [iterable](https://docs.python.org/3/glossary.html#term-iterable) container, such as a list"
@@ -65,7 +65,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c94f91f4",
+ "id": "fbb02b73",
"metadata": {},
"outputs": [],
"source": [
@@ -74,7 +74,7 @@
},
{
"cell_type": "markdown",
- "id": "c3bb8f77",
+ "id": "c1329bd5",
"metadata": {},
"source": [
"You can also add nodes along with node\n",
@@ -96,7 +96,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "02cbbc70",
+ "id": "9f7ed036",
"metadata": {},
"outputs": [],
"source": [
@@ -106,7 +106,7 @@
},
{
"cell_type": "markdown",
- "id": "cb2c969c",
+ "id": "352e5eb2",
"metadata": {},
"source": [
"`G` now contains the nodes of `H` as nodes of `G`.\n",
@@ -116,7 +116,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ac9270c8",
+ "id": "70997bf3",
"metadata": {},
"outputs": [],
"source": [
@@ -125,7 +125,7 @@
},
{
"cell_type": "markdown",
- "id": "13828256",
+ "id": "d6b38e18",
"metadata": {},
"source": [
"The graph `G` now contains `H` as a node. This flexibility is very powerful as\n",
@@ -143,7 +143,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "a8284de6",
+ "id": "9eea36b7",
"metadata": {},
"outputs": [],
"source": [
@@ -154,7 +154,7 @@
},
{
"cell_type": "markdown",
- "id": "ff5cffab",
+ "id": "b464b93d",
"metadata": {},
"source": [
"by adding a list of edges,"
@@ -163,7 +163,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "434d2f22",
+ "id": "34f152ab",
"metadata": {},
"outputs": [],
"source": [
@@ -172,7 +172,7 @@
},
{
"cell_type": "markdown",
- "id": "65f9fc56",
+ "id": "9f21d2b4",
"metadata": {},
"source": [
"or by adding any ebunch of edges. An *ebunch* is any iterable\n",
@@ -185,7 +185,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "54bfa016",
+ "id": "043d9118",
"metadata": {},
"outputs": [],
"source": [
@@ -194,7 +194,7 @@
},
{
"cell_type": "markdown",
- "id": "302b1072",
+ "id": "b0e6b3d0",
"metadata": {},
"source": [
"There are no complaints when adding existing nodes or edges. For example,\n",
@@ -204,7 +204,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "191ec7af",
+ "id": "a7803e90",
"metadata": {},
"outputs": [],
"source": [
@@ -213,7 +213,7 @@
},
{
"cell_type": "markdown",
- "id": "bafe4169",
+ "id": "ddf6cae4",
"metadata": {},
"source": [
"we add new nodes/edges and NetworkX quietly ignores any that are\n",
@@ -223,7 +223,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "c0011fb9",
+ "id": "7200f52c",
"metadata": {},
"outputs": [],
"source": [
@@ -237,7 +237,7 @@
},
{
"cell_type": "markdown",
- "id": "acde4534",
+ "id": "b5b9201c",
"metadata": {},
"source": [
"At this stage the graph `G` consists of 8 nodes and 3 edges, as can be seen by:"
@@ -246,7 +246,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "401d89be",
+ "id": "a5ee0237",
"metadata": {},
"outputs": [],
"source": [
@@ -257,7 +257,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5b28cc93",
+ "id": "f3096427",
"metadata": {},
"outputs": [],
"source": [
@@ -272,7 +272,7 @@
},
{
"cell_type": "markdown",
- "id": "b66f2b7b",
+ "id": "f2250e7f",
"metadata": {},
"source": [
"# Examining elements of a graph\n",
@@ -292,7 +292,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "b44501af",
+ "id": "50bbc2f9",
"metadata": {},
"outputs": [],
"source": [
@@ -304,7 +304,7 @@
},
{
"cell_type": "markdown",
- "id": "7b82fc28",
+ "id": "af406d27",
"metadata": {},
"source": [
"One can specify to report the edges and degree from a subset of all nodes\n",
@@ -316,7 +316,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "8ca5a782",
+ "id": "b9a24473",
"metadata": {},
"outputs": [],
"source": [
@@ -326,7 +326,7 @@
},
{
"cell_type": "markdown",
- "id": "02b3e41c",
+ "id": "9277ad57",
"metadata": {},
"source": [
"# Removing elements from a graph\n",
@@ -343,7 +343,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "a36cce3a",
+ "id": "2e9d83af",
"metadata": {},
"outputs": [],
"source": [
@@ -355,7 +355,7 @@
},
{
"cell_type": "markdown",
- "id": "1e28330a",
+ "id": "20eaa24a",
"metadata": {},
"source": [
"# Using the graph constructors\n",
@@ -370,7 +370,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "9d0879b5",
+ "id": "086e518e",
"metadata": {},
"outputs": [],
"source": [
@@ -387,7 +387,7 @@
},
{
"cell_type": "markdown",
- "id": "b6c57366",
+ "id": "715a10d5",
"metadata": {},
"source": [
"# What to use as nodes and edges\n",
@@ -416,7 +416,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "4b6b4cc9",
+ "id": "ef2ac6b1",
"metadata": {},
"outputs": [],
"source": [
@@ -428,7 +428,7 @@
},
{
"cell_type": "markdown",
- "id": "4ef3c002",
+ "id": "3dc01db8",
"metadata": {},
"source": [
"You can get/set the attributes of an edge using subscript notation\n",
@@ -438,7 +438,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "3af8cd3d",
+ "id": "9a28c088",
"metadata": {},
"outputs": [],
"source": [
@@ -450,7 +450,7 @@
},
{
"cell_type": "markdown",
- "id": "a38aad14",
+ "id": "5d9371d4",
"metadata": {},
"source": [
"Fast examination of all (node, adjacency) pairs is achieved using\n",
@@ -461,7 +461,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "78900827",
+ "id": "4a1ceee5",
"metadata": {},
"outputs": [],
"source": [
@@ -475,7 +475,7 @@
},
{
"cell_type": "markdown",
- "id": "175a41b6",
+ "id": "a85bf73b",
"metadata": {},
"source": [
"Convenient access to all edges is achieved with the edges property."
@@ -484,7 +484,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "d0230f15",
+ "id": "a83a3c2c",
"metadata": {},
"outputs": [],
"source": [
@@ -495,7 +495,7 @@
},
{
"cell_type": "markdown",
- "id": "44de1952",
+ "id": "b485a1c1",
"metadata": {},
"source": [
"# Adding attributes to graphs, nodes, and edges\n",
@@ -517,7 +517,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "303386dd",
+ "id": "1937ca75",
"metadata": {},
"outputs": [],
"source": [
@@ -527,7 +527,7 @@
},
{
"cell_type": "markdown",
- "id": "b96ad4a8",
+ "id": "96061e33",
"metadata": {},
"source": [
"Or you can modify attributes later"
@@ -536,7 +536,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "55ece8fb",
+ "id": "bdc65098",
"metadata": {},
"outputs": [],
"source": [
@@ -546,7 +546,7 @@
},
{
"cell_type": "markdown",
- "id": "d0ee2386",
+ "id": "013ee034",
"metadata": {},
"source": [
"# Node attributes\n",
@@ -557,7 +557,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "7490d9bc",
+ "id": "5f30fb34",
"metadata": {},
"outputs": [],
"source": [
@@ -570,7 +570,7 @@
},
{
"cell_type": "markdown",
- "id": "aa13f2c9",
+ "id": "e6cdd75a",
"metadata": {},
"source": [
"Note that adding a node to `G.nodes` does not add it to the graph, use\n",
@@ -585,7 +585,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "086fe04c",
+ "id": "0d67c3ae",
"metadata": {},
"outputs": [],
"source": [
@@ -598,7 +598,7 @@
},
{
"cell_type": "markdown",
- "id": "d79874d3",
+ "id": "96fa928f",
"metadata": {},
"source": [
"The special attribute `weight` should be numeric as it is used by\n",
@@ -619,7 +619,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "14fab3bc",
+ "id": "83d74f74",
"metadata": {},
"outputs": [],
"source": [
@@ -633,7 +633,7 @@
},
{
"cell_type": "markdown",
- "id": "c7dd6481",
+ "id": "be22350a",
"metadata": {},
"source": [
"Some algorithms work only for directed graphs and others are not well\n",
@@ -646,7 +646,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "07fb35fc",
+ "id": "7f9d17cf",
"metadata": {},
"outputs": [],
"source": [
@@ -655,7 +655,7 @@
},
{
"cell_type": "markdown",
- "id": "9cda3f7d",
+ "id": "258a0a35",
"metadata": {},
"source": [
"# Multigraphs\n",
@@ -675,7 +675,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "8d607698",
+ "id": "b7d8bd66",
"metadata": {},
"outputs": [],
"source": [
@@ -693,7 +693,7 @@
},
{
"cell_type": "markdown",
- "id": "1274128a",
+ "id": "c8621f50",
"metadata": {},
"source": [
"# Graph generators and graph operations\n",
@@ -713,7 +713,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "bf4e008d",
+ "id": "3e5e0ff5",
"metadata": {},
"outputs": [],
"source": [
@@ -725,7 +725,7 @@
},
{
"cell_type": "markdown",
- "id": "673279c6",
+ "id": "3943038c",
"metadata": {},
"source": [
"# 4. Using a stochastic graph generator, e.g,\n",
@@ -736,7 +736,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "fd2feef4",
+ "id": "439a61bd",
"metadata": {},
"outputs": [],
"source": [
@@ -748,7 +748,7 @@
},
{
"cell_type": "markdown",
- "id": "703ea6be",
+ "id": "7bc4b49a",
"metadata": {},
"source": [
"# 5. Reading a graph stored in a file using common graph formats\n",
@@ -760,7 +760,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "bb8090e6",
+ "id": "740569d3",
"metadata": {},
"outputs": [],
"source": [
@@ -770,7 +770,7 @@
},
{
"cell_type": "markdown",
- "id": "973a9b9f",
+ "id": "5ecfcaf4",
"metadata": {},
"source": [
"For details on graph formats see Reading and writing graphs\n",
@@ -785,7 +785,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "26e8238c",
+ "id": "f8750762",
"metadata": {},
"outputs": [],
"source": [
@@ -799,7 +799,7 @@
},
{
"cell_type": "markdown",
- "id": "1def3479",
+ "id": "77d7137b",
"metadata": {},
"source": [
"Some functions with large output iterate over (node, value) 2-tuples.\n",
@@ -809,7 +809,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "58e06fa5",
+ "id": "b96e8565",
"metadata": {},
"outputs": [],
"source": [
@@ -819,7 +819,7 @@
},
{
"cell_type": "markdown",
- "id": "14a94ada",
+ "id": "13102485",
"metadata": {},
"source": [
"See Algorithms for details on graph algorithms\n",
@@ -838,7 +838,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "07f88ce4",
+ "id": "0d23c39c",
"metadata": {},
"outputs": [],
"source": [
@@ -847,7 +847,7 @@
},
{
"cell_type": "markdown",
- "id": "d9234a34",
+ "id": "3cea4268",
"metadata": {},
"source": [
"To test if the import of `nx_pylab` was successful draw `G`\n",
@@ -857,7 +857,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "43e21e1a",
+ "id": "12db14b2",
"metadata": {},
"outputs": [],
"source": [
@@ -870,7 +870,7 @@
},
{
"cell_type": "markdown",
- "id": "e7940816",
+ "id": "d528e97f",
"metadata": {},
"source": [
"when drawing to an interactive display. Note that you may need to issue a\n",
@@ -880,7 +880,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "bad8ba76",
+ "id": "a261f16e",
"metadata": {},
"outputs": [],
"source": [
@@ -889,7 +889,7 @@
},
{
"cell_type": "markdown",
- "id": "4b162725",
+ "id": "01288888",
"metadata": {},
"source": [
"command if you are not using matplotlib in interactive mode."
@@ -898,7 +898,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "8a183e56",
+ "id": "64936191",
"metadata": {},
"outputs": [],
"source": [
@@ -919,7 +919,7 @@
},
{
"cell_type": "markdown",
- "id": "d91f5713",
+ "id": "0091f94a",
"metadata": {},
"source": [
"You can find additional options via `draw_networkx()` and\n",
@@ -930,7 +930,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "7635ed9d",
+ "id": "52b43d16",
"metadata": {},
"outputs": [],
"source": [
@@ -941,7 +941,7 @@
},
{
"cell_type": "markdown",
- "id": "22d018cc",
+ "id": "d883d5f7",
"metadata": {},
"source": [
"To save drawings to a file, use, for example"
@@ -950,7 +950,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "47c0c750",
+ "id": "6ce05699",
"metadata": {},
"outputs": [],
"source": [
@@ -960,7 +960,7 @@
},
{
"cell_type": "markdown",
- "id": "cc4da952",
+ "id": "4cb4ddfe",
"metadata": {},
"source": [
"This function writes to the file `path.png` in the local directory. If Graphviz and\n",
@@ -973,7 +973,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "34997105",
+ "id": "4da90442",
"metadata": {},
"outputs": [],
"source": [
@@ -985,7 +985,7 @@
},
{
"cell_type": "markdown",
- "id": "e4d99944",
+ "id": "259ad362",
"metadata": {},
"source": [
"See Drawing for additional details.\n",