Executing black over all jupyter notebook (#190)

Reverting black for the jupyter notebooks gets old. Can we just run
black over all of them?
This commit is contained in:
2023-10-04 20:03:47 +02:00
committed by GitHub
parent 030ad00c7d
commit 41f2c9f995
15 changed files with 658 additions and 487 deletions

View File

@ -92,39 +92,40 @@
"G = nx.MultiGraph()\n",
"\n",
"# create list of nodes with attributes as a dictionary\n",
"nodes = [(1, {'label': 'Firma 1', 'branche': 'Branche 1', 'land': 'Land 1'}), \n",
" (2, {'label': 'Firma 2', 'branche': 'Branche 1', 'land': 'Land 2'}),\n",
" (3, {'label': 'Firma 3', 'branche': 'Branche 1', 'land': 'Land 3'}),\n",
" (4, {'label': 'Firma 4', 'branche': 'Branche 2', 'land': 'Land 4'}),\n",
" (5, {'label': 'Firma 5', 'branche': 'Branche 2', 'land': 'Land 1'}),\n",
" (6, {'label': 'Firma 6', 'branche': 'Branche 2', 'land': 'Land 3'}),\n",
" (7, {'label': 'Firma 7', 'branche': 'Branche 3', 'land': 'Land 3'}),\n",
" (8, {'label': 'Firma 8', 'branche': 'Branche 3', 'land': 'Land 2'}),\n",
" (9, {'label': 'Firma 9', 'branche': 'Branche 4', 'land': 'Land 1'}),\n",
" (10, {'label': 'Firma 10', 'branche': 'Branche 4', 'land': 'Land 4'}),\n",
" ]\n",
"nodes = [\n",
" (1, {\"label\": \"Firma 1\", \"branche\": \"Branche 1\", \"land\": \"Land 1\"}),\n",
" (2, {\"label\": \"Firma 2\", \"branche\": \"Branche 1\", \"land\": \"Land 2\"}),\n",
" (3, {\"label\": \"Firma 3\", \"branche\": \"Branche 1\", \"land\": \"Land 3\"}),\n",
" (4, {\"label\": \"Firma 4\", \"branche\": \"Branche 2\", \"land\": \"Land 4\"}),\n",
" (5, {\"label\": \"Firma 5\", \"branche\": \"Branche 2\", \"land\": \"Land 1\"}),\n",
" (6, {\"label\": \"Firma 6\", \"branche\": \"Branche 2\", \"land\": \"Land 3\"}),\n",
" (7, {\"label\": \"Firma 7\", \"branche\": \"Branche 3\", \"land\": \"Land 3\"}),\n",
" (8, {\"label\": \"Firma 8\", \"branche\": \"Branche 3\", \"land\": \"Land 2\"}),\n",
" (9, {\"label\": \"Firma 9\", \"branche\": \"Branche 4\", \"land\": \"Land 1\"}),\n",
" (10, {\"label\": \"Firma 10\", \"branche\": \"Branche 4\", \"land\": \"Land 4\"}),\n",
"]\n",
"\n",
"# create list of edges with attributes as a dictionary\n",
"edges = [\n",
" (1, 2, {'label': 'beziehung1'}), \n",
" (5, 2, {'label': 'beziehung2'}), \n",
" (1, 3, {'label': 'beziehung3'}), \n",
" (2, 4, {'label': 'beziehung3'}), \n",
" (2, 6, {'label': 'beziehung4'}), \n",
" (2, 5, {'label': 'beziehung4'}),\n",
" (8, 10, {'label': 'beziehung4'}),\n",
" (9, 10, {'label': 'beziehung3'}), \n",
" (3, 7, {'label': 'beziehung2'}), \n",
" (6, 8, {'label': 'beziehung1'}), \n",
" (6, 9, {'label': 'beziehung1'}), \n",
" (1, 6, {'label': 'beziehung2'})\n",
" ]\n",
" (1, 2, {\"label\": \"beziehung1\"}),\n",
" (5, 2, {\"label\": \"beziehung2\"}),\n",
" (1, 3, {\"label\": \"beziehung3\"}),\n",
" (2, 4, {\"label\": \"beziehung3\"}),\n",
" (2, 6, {\"label\": \"beziehung4\"}),\n",
" (2, 5, {\"label\": \"beziehung4\"}),\n",
" (8, 10, {\"label\": \"beziehung4\"}),\n",
" (9, 10, {\"label\": \"beziehung3\"}),\n",
" (3, 7, {\"label\": \"beziehung2\"}),\n",
" (6, 8, {\"label\": \"beziehung1\"}),\n",
" (6, 9, {\"label\": \"beziehung1\"}),\n",
" (1, 6, {\"label\": \"beziehung2\"}),\n",
"]\n",
"\n",
"# add nodes to the graph\n",
"G.add_nodes_from(nodes)\n",
"\n",
"# add edges to the graph, to hide arrow heads of the edges use option arrows = 'false'\n",
"G.add_edges_from(edges, arrows = 'false')"
"G.add_edges_from(edges, arrows=\"false\")"
]
},
{
@ -147,7 +148,9 @@
"outputs": [],
"source": [
"for node in G.nodes:\n",
" G.nodes[node]['title'] = G.nodes[node]['label'] + '\\n' + 'Anzahl Verbindungen: ' + str(G.degree[node])"
" G.nodes[node][\"title\"] = (\n",
" G.nodes[node][\"label\"] + \"\\n\" + \"Anzahl Verbindungen: \" + str(G.degree[node])\n",
" )"
]
},
{
@ -206,16 +209,16 @@
"outputs": [],
"source": [
"# scaling the size of the nodes by 5*degree\n",
"scale = 5 \n",
"scale = 5\n",
"\n",
"# getting all nodes and their number of connections\n",
"d = dict(G.degree)\n",
"\n",
"# updating dict\n",
"d.update((x, scale*(y+1)) for x, y in d.items())\n",
"d.update((x, scale * (y + 1)) for x, y in d.items())\n",
"\n",
"# setting size attribute according to created dictionary\n",
"nx.set_node_attributes(G,d,'size')"
"nx.set_node_attributes(G, d, \"size\")"
]
},
{
@ -236,10 +239,17 @@
"from pyvis.network import Network\n",
"\n",
"# create network, 'directed = true' allows multiple edges between nodes\n",
"nt = Network('1000px', '1000px', neighborhood_highlight=True, notebook=True, cdn_resources='in_line', directed=True)\n",
"nt = Network(\n",
" \"1000px\",\n",
" \"1000px\",\n",
" neighborhood_highlight=True,\n",
" notebook=True,\n",
" cdn_resources=\"in_line\",\n",
" directed=True,\n",
")\n",
"\n",
"# populates the nodes and edges data structures\n",
"nt.from_nx(G)\n"
"nt.from_nx(G)"
]
},
{
@ -275,25 +285,28 @@
"outputs": [],
"source": [
"# define new function that sets the color of the nodes\n",
"def color_type (net, type):\n",
" ''' color_type sets the color of a network depending on an attribute of the nodes\n",
" net: network\n",
" type: 'branche' or 'land' '''\n",
"def color_type(net, type):\n",
" \"\"\"color_type sets the color of a network depending on an attribute of the nodes\n",
" net: network\n",
" type: 'branche' or 'land'\"\"\"\n",
"\n",
" colormap = {'Branche 1': '#87CEEB',\n",
" 'Branche 2': '#0f4c81',\n",
" 'Branche 3': '#B2FFFF', \n",
" 'Branche 4': '#191970',\n",
" 'Land 1': '#F8D568', \n",
" 'Land 2': '#F58025', \n",
" 'Land 3': '#CC5500', \n",
" 'Land 4': '#C0362C'}\n",
" colormap = {\n",
" \"Branche 1\": \"#87CEEB\",\n",
" \"Branche 2\": \"#0f4c81\",\n",
" \"Branche 3\": \"#B2FFFF\",\n",
" \"Branche 4\": \"#191970\",\n",
" \"Land 1\": \"#F8D568\",\n",
" \"Land 2\": \"#F58025\",\n",
" \"Land 3\": \"#CC5500\",\n",
" \"Land 4\": \"#C0362C\",\n",
" }\n",
" for node in net.nodes:\n",
" node['color'] = colormap[node[type]]\n",
" node[\"color\"] = colormap[node[type]]\n",
" return net\n",
"\n",
"\n",
"# set color based on attribute\n",
"nt = color_type(nt, 'branche')"
"nt = color_type(nt, \"branche\")"
]
},
{
@ -310,8 +323,8 @@
"metadata": {},
"outputs": [],
"source": [
"# set all edge colors \n",
"nt.options.edges.color = 'grey'"
"# set all edge colors\n",
"nt.options.edges.color = \"grey\""
]
},
{
@ -360,13 +373,20 @@
],
"source": [
"# activate physics options to try out different solver\n",
"#nt.show_buttons(filter_=['physics'])\n",
"# nt.show_buttons(filter_=['physics'])\n",
"\n",
"# set physics options\n",
"nt.barnes_hut(gravity=-8000, central_gravity=0.3, spring_length=200, spring_strength=0.1, damping=0.09, overlap=0)\n",
"nt.barnes_hut(\n",
" gravity=-8000,\n",
" central_gravity=0.3,\n",
" spring_length=200,\n",
" spring_strength=0.1,\n",
" damping=0.09,\n",
" overlap=0,\n",
")\n",
"\n",
"# create html and save in same folder\n",
"nt.show('Netzwerk_Verflechtungsanalyse.html')"
"nt.show(\"Netzwerk_Verflechtungsanalyse.html\")"
]
},
{
@ -416,16 +436,16 @@
"from pyvis.network import Network\n",
"\n",
"sn = nx.Graph()\n",
"sn_nodes = [1,2,3,4,5,6,7]\n",
"sn_edges = [(1,4),(2,4),(3,4),(4,5),(5,6),(5,7)]\n",
"sn_nodes = [1, 2, 3, 4, 5, 6, 7]\n",
"sn_edges = [(1, 4), (2, 4), (3, 4), (4, 5), (5, 6), (5, 7)]\n",
"\n",
"sn.add_nodes_from(sn_nodes, color = '#00509b')\n",
"sn.add_nodes_from(sn_nodes, color=\"#00509b\")\n",
"sn.add_edges_from(sn_edges)\n",
"\n",
"net = Network('1000px', '1000px', notebook=True, cdn_resources='in_line')\n",
"net = Network(\"1000px\", \"1000px\", notebook=True, cdn_resources=\"in_line\")\n",
"\n",
"net.from_nx(sn)\n",
"net.show('Netzwerk.html')\n"
"net.show(\"Netzwerk.html\")"
]
}
],