Skip to content

Commit

Permalink
fixed igrph section of the notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
andremann committed Mar 20, 2024
1 parent 03967aa commit 0989dda
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
Binary file removed .DS_Store
Binary file not shown.
78 changes: 67 additions & 11 deletions notebooks/beginners_kit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Results can modeled as graph and analysed."
"Results can be modeled as a graph and analysed. Let's try doing so with igraph and feed it with country couples and the number of coparticipated projects."
]
},
{
Expand All @@ -968,6 +968,13 @@
" directed=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's find the number of nodes in the graph."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -977,6 +984,13 @@
"G.vcount()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's find the number of edges."
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -986,6 +1000,13 @@
"G.ecount()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A generic node can be inspected like so"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -995,6 +1016,13 @@
"G.vs[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Instead, a generic edge can be inspected with"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -1004,15 +1032,32 @@
"G.es[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ok. Let's try to plot something. The whole network looks like this."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"fig, ax = plt.subplots()\n",
"ig.plot(G, vertex_label=G.vs['countrycode'], target=ax)"
"import numpy as np\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 10))\n",
"max_w = np.max(G.es['weight'])\n",
"ig.plot(G, vertex_label=G.vs['countrycode'], vertex_size=10, edge_width=2, edge_color='gray', target=ax)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's filter by country, say Italy (i.e., IT)"
]
},
{
Expand All @@ -1021,7 +1066,8 @@
"metadata": {},
"outputs": [],
"source": [
"G.vs.find(countrycode_eq = 'MY') # maldives"
"H = G.induced_subgraph(G.neighborhood(G.vs.find(countrycode_eq = 'IT')))\n",
"H.summary()"
]
},
{
Expand All @@ -1030,8 +1076,17 @@
"metadata": {},
"outputs": [],
"source": [
"H = G.induced_subgraph(G.neighborhood(50))\n",
"H.summary()"
"H.vs['color'] = 'blue'\n",
"H.vs.find(countrycode_eq = 'IT')['color'] = 'red'\n",
"fig, ax = plt.subplots(figsize=(10, 10))\n",
"ig.plot(H, vertex_label=H.vs['countrycode'], vertex_size=30, edge_width=2, edge_color='gray',target=ax)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Still a lot of collaborations there. Let's plot a country with less collaborations, say Maldives (i.e., MV)."
]
},
{
Expand All @@ -1040,10 +1095,8 @@
"metadata": {},
"outputs": [],
"source": [
"H.vs['color'] = 'grey'\n",
"H.vs[0]['color'] = 'red'\n",
"fig, ax = plt.subplots()\n",
"ig.plot(H, target=ax)"
"H = G.induced_subgraph(G.neighborhood(G.vs.find(countrycode_eq = 'MV'))) # Maldives\n",
"H.summary()"
]
},
{
Expand All @@ -1052,7 +1105,10 @@
"metadata": {},
"outputs": [],
"source": [
"G.transitivity_local_undirected(50)"
"H.vs['color'] = 'blue'\n",
"H.vs.find(countrycode_eq = 'MV')['color'] = 'red'\n",
"fig, ax = plt.subplots(figsize=(10, 10))\n",
"ig.plot(H, vertex_label=H.vs['countrycode'], vertex_size=30, edge_width=2, edge_color='gray',target=ax)"
]
},
{
Expand Down

0 comments on commit 0989dda

Please sign in to comment.