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 35064095..9f5ce5b0 100644
--- a/tutorial.ipynb
+++ b/tutorial.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
- "id": "faf90572",
+ "id": "34932fcf",
"metadata": {},
"source": [
"## Tutorial\n",
@@ -17,7 +17,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "509e60e1",
+ "id": "cd473e7d",
"metadata": {},
"outputs": [],
"source": [
@@ -27,7 +27,7 @@
},
{
"cell_type": "markdown",
- "id": "8f16129b",
+ "id": "7ec0c903",
"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": "bd6562e0",
+ "id": "e41d4029",
"metadata": {},
"outputs": [],
"source": [
@@ -56,7 +56,7 @@
},
{
"cell_type": "markdown",
- "id": "2d825f0d",
+ "id": "66c6ec7a",
"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": "fbb02b73",
+ "id": "69712d73",
"metadata": {},
"outputs": [],
"source": [
@@ -74,7 +74,7 @@
},
{
"cell_type": "markdown",
- "id": "c1329bd5",
+ "id": "cb7b2f97",
"metadata": {},
"source": [
"You can also add nodes along with node\n",
@@ -96,7 +96,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "9f7ed036",
+ "id": "1c7f7b4d",
"metadata": {},
"outputs": [],
"source": [
@@ -106,7 +106,7 @@
},
{
"cell_type": "markdown",
- "id": "352e5eb2",
+ "id": "5cdb5f87",
"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": "70997bf3",
+ "id": "13fe2579",
"metadata": {},
"outputs": [],
"source": [
@@ -125,7 +125,7 @@
},
{
"cell_type": "markdown",
- "id": "d6b38e18",
+ "id": "667e7ee1",
"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": "9eea36b7",
+ "id": "8f1ea633",
"metadata": {},
"outputs": [],
"source": [
@@ -154,7 +154,7 @@
},
{
"cell_type": "markdown",
- "id": "b464b93d",
+ "id": "afd13aa3",
"metadata": {},
"source": [
"by adding a list of edges,"
@@ -163,7 +163,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "34f152ab",
+ "id": "b255bc0a",
"metadata": {},
"outputs": [],
"source": [
@@ -172,7 +172,7 @@
},
{
"cell_type": "markdown",
- "id": "9f21d2b4",
+ "id": "4f7607ce",
"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": "043d9118",
+ "id": "e8759a73",
"metadata": {},
"outputs": [],
"source": [
@@ -194,7 +194,7 @@
},
{
"cell_type": "markdown",
- "id": "b0e6b3d0",
+ "id": "e55e991c",
"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": "a7803e90",
+ "id": "721e72aa",
"metadata": {},
"outputs": [],
"source": [
@@ -213,7 +213,7 @@
},
{
"cell_type": "markdown",
- "id": "ddf6cae4",
+ "id": "785468a4",
"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": "7200f52c",
+ "id": "bbd2a149",
"metadata": {},
"outputs": [],
"source": [
@@ -237,7 +237,7 @@
},
{
"cell_type": "markdown",
- "id": "b5b9201c",
+ "id": "b7ab412e",
"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": "a5ee0237",
+ "id": "cca6ffec",
"metadata": {},
"outputs": [],
"source": [
@@ -257,7 +257,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f3096427",
+ "id": "eb8820e7",
"metadata": {},
"outputs": [],
"source": [
@@ -272,7 +272,7 @@
},
{
"cell_type": "markdown",
- "id": "f2250e7f",
+ "id": "5eece4bf",
"metadata": {},
"source": [
"# Examining elements of a graph\n",
@@ -292,7 +292,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "50bbc2f9",
+ "id": "600d36b9",
"metadata": {},
"outputs": [],
"source": [
@@ -304,7 +304,7 @@
},
{
"cell_type": "markdown",
- "id": "af406d27",
+ "id": "eb62ccb2",
"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": "b9a24473",
+ "id": "02948235",
"metadata": {},
"outputs": [],
"source": [
@@ -326,7 +326,7 @@
},
{
"cell_type": "markdown",
- "id": "9277ad57",
+ "id": "c0da2d03",
"metadata": {},
"source": [
"# Removing elements from a graph\n",
@@ -343,7 +343,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "2e9d83af",
+ "id": "16a7ac54",
"metadata": {},
"outputs": [],
"source": [
@@ -355,7 +355,7 @@
},
{
"cell_type": "markdown",
- "id": "20eaa24a",
+ "id": "9ad77ea0",
"metadata": {},
"source": [
"# Using the graph constructors\n",
@@ -370,7 +370,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "086e518e",
+ "id": "3a4f5043",
"metadata": {},
"outputs": [],
"source": [
@@ -387,7 +387,7 @@
},
{
"cell_type": "markdown",
- "id": "715a10d5",
+ "id": "d561f022",
"metadata": {},
"source": [
"# What to use as nodes and edges\n",
@@ -416,7 +416,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "ef2ac6b1",
+ "id": "258013e9",
"metadata": {},
"outputs": [],
"source": [
@@ -428,7 +428,7 @@
},
{
"cell_type": "markdown",
- "id": "3dc01db8",
+ "id": "de58f6ba",
"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": "9a28c088",
+ "id": "b8ca122e",
"metadata": {},
"outputs": [],
"source": [
@@ -450,7 +450,7 @@
},
{
"cell_type": "markdown",
- "id": "5d9371d4",
+ "id": "6d44fd70",
"metadata": {},
"source": [
"Fast examination of all (node, adjacency) pairs is achieved using\n",
@@ -461,7 +461,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "4a1ceee5",
+ "id": "edf3809c",
"metadata": {},
"outputs": [],
"source": [
@@ -475,7 +475,7 @@
},
{
"cell_type": "markdown",
- "id": "a85bf73b",
+ "id": "4de66c10",
"metadata": {},
"source": [
"Convenient access to all edges is achieved with the edges property."
@@ -484,7 +484,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "a83a3c2c",
+ "id": "4cd1760c",
"metadata": {},
"outputs": [],
"source": [
@@ -495,7 +495,7 @@
},
{
"cell_type": "markdown",
- "id": "b485a1c1",
+ "id": "eba6152a",
"metadata": {},
"source": [
"# Adding attributes to graphs, nodes, and edges\n",
@@ -517,7 +517,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "1937ca75",
+ "id": "65e41d33",
"metadata": {},
"outputs": [],
"source": [
@@ -527,7 +527,7 @@
},
{
"cell_type": "markdown",
- "id": "96061e33",
+ "id": "a8900dcd",
"metadata": {},
"source": [
"Or you can modify attributes later"
@@ -536,7 +536,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "bdc65098",
+ "id": "4aed51f0",
"metadata": {},
"outputs": [],
"source": [
@@ -546,7 +546,7 @@
},
{
"cell_type": "markdown",
- "id": "013ee034",
+ "id": "f1ae5957",
"metadata": {},
"source": [
"# Node attributes\n",
@@ -557,7 +557,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "5f30fb34",
+ "id": "41e0f958",
"metadata": {},
"outputs": [],
"source": [
@@ -570,7 +570,7 @@
},
{
"cell_type": "markdown",
- "id": "e6cdd75a",
+ "id": "6d1541aa",
"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": "0d67c3ae",
+ "id": "405ad7d8",
"metadata": {},
"outputs": [],
"source": [
@@ -598,7 +598,7 @@
},
{
"cell_type": "markdown",
- "id": "96fa928f",
+ "id": "89ae6128",
"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": "83d74f74",
+ "id": "f1a70f53",
"metadata": {},
"outputs": [],
"source": [
@@ -633,7 +633,7 @@
},
{
"cell_type": "markdown",
- "id": "be22350a",
+ "id": "31d5f5b3",
"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": "7f9d17cf",
+ "id": "a917af82",
"metadata": {},
"outputs": [],
"source": [
@@ -655,7 +655,7 @@
},
{
"cell_type": "markdown",
- "id": "258a0a35",
+ "id": "88026fea",
"metadata": {},
"source": [
"# Multigraphs\n",
@@ -675,7 +675,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "b7d8bd66",
+ "id": "057492be",
"metadata": {},
"outputs": [],
"source": [
@@ -693,7 +693,7 @@
},
{
"cell_type": "markdown",
- "id": "c8621f50",
+ "id": "a884bc8b",
"metadata": {},
"source": [
"# Graph generators and graph operations\n",
@@ -713,7 +713,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "3e5e0ff5",
+ "id": "7d6536ed",
"metadata": {},
"outputs": [],
"source": [
@@ -725,7 +725,7 @@
},
{
"cell_type": "markdown",
- "id": "3943038c",
+ "id": "ae1c1e80",
"metadata": {},
"source": [
"# 4. Using a stochastic graph generator, e.g,\n",
@@ -736,7 +736,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "439a61bd",
+ "id": "e79c3dcf",
"metadata": {},
"outputs": [],
"source": [
@@ -748,7 +748,7 @@
},
{
"cell_type": "markdown",
- "id": "7bc4b49a",
+ "id": "ae0d8913",
"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": "740569d3",
+ "id": "1e573388",
"metadata": {},
"outputs": [],
"source": [
@@ -770,7 +770,7 @@
},
{
"cell_type": "markdown",
- "id": "5ecfcaf4",
+ "id": "408a62d1",
"metadata": {},
"source": [
"For details on graph formats see Reading and writing graphs\n",
@@ -785,7 +785,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "f8750762",
+ "id": "e34295a8",
"metadata": {},
"outputs": [],
"source": [
@@ -799,7 +799,7 @@
},
{
"cell_type": "markdown",
- "id": "77d7137b",
+ "id": "a61c4b28",
"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": "b96e8565",
+ "id": "3a801a03",
"metadata": {},
"outputs": [],
"source": [
@@ -819,7 +819,7 @@
},
{
"cell_type": "markdown",
- "id": "13102485",
+ "id": "ffc65f46",
"metadata": {},
"source": [
"See Algorithms for details on graph algorithms\n",
@@ -838,7 +838,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "0d23c39c",
+ "id": "e9d65ba2",
"metadata": {},
"outputs": [],
"source": [
@@ -847,7 +847,7 @@
},
{
"cell_type": "markdown",
- "id": "3cea4268",
+ "id": "7785478f",
"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": "12db14b2",
+ "id": "96c82e83",
"metadata": {},
"outputs": [],
"source": [
@@ -870,7 +870,7 @@
},
{
"cell_type": "markdown",
- "id": "d528e97f",
+ "id": "9852dd9d",
"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": "a261f16e",
+ "id": "a9969348",
"metadata": {},
"outputs": [],
"source": [
@@ -889,7 +889,7 @@
},
{
"cell_type": "markdown",
- "id": "01288888",
+ "id": "c87db54f",
"metadata": {},
"source": [
"command if you are not using matplotlib in interactive mode."
@@ -898,7 +898,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "64936191",
+ "id": "0f6044ed",
"metadata": {},
"outputs": [],
"source": [
@@ -919,7 +919,7 @@
},
{
"cell_type": "markdown",
- "id": "0091f94a",
+ "id": "d9538900",
"metadata": {},
"source": [
"You can find additional options via `draw_networkx()` and\n",
@@ -930,7 +930,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "52b43d16",
+ "id": "3d0ed48a",
"metadata": {},
"outputs": [],
"source": [
@@ -941,7 +941,7 @@
},
{
"cell_type": "markdown",
- "id": "d883d5f7",
+ "id": "71d93c4e",
"metadata": {},
"source": [
"To save drawings to a file, use, for example"
@@ -950,7 +950,7 @@
{
"cell_type": "code",
"execution_count": null,
- "id": "6ce05699",
+ "id": "61c0860c",
"metadata": {},
"outputs": [],
"source": [
@@ -960,7 +960,7 @@
},
{
"cell_type": "markdown",
- "id": "4cb4ddfe",
+ "id": "b386763c",
"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": "4da90442",
+ "id": "03e31283",
"metadata": {},
"outputs": [],
"source": [
@@ -985,7 +985,7 @@
},
{
"cell_type": "markdown",
- "id": "259ad362",
+ "id": "a8d17590",
"metadata": {},
"source": [
"See Drawing for additional details.\n",