IIabm/LoadNetworkx_20230210-1.ipynb

137 lines
2.8 MiB
Plaintext
Raw Normal View History

2023-02-12 21:44:08 +08:00
{
"cells": [
{
"cell_type": "code",
2023-02-25 20:14:53 +08:00
"execution_count": 1,
2023-02-12 21:44:08 +08:00
"metadata": {},
"outputs": [
{
"data": {
2023-02-25 20:14:53 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAACyIAAAsQCAYAAABS037aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdeZidZWE3/u85Z9ZMkpmsJISwy74WCyoiuC9135fa0lpba9tXbdXaxda2v7dVtK3Wvta64q4URRGBooCAQNhJSCBhzb4vs69n+f1xJpMMSYAjm8Lnc125MvMs93M/93POcDF8z5dCrVarBQAAAAAAAAAAAACgAcUnewIAAAAAAAAAAAAAwK8fQWQAAAAAAAAAAAAAoGGCyAAAAAAAAAAAAABAwwSRAQAAAAAAAAAAAICGCSIDAAAAAAAAAAAAAA0TRAYAAAAAAAAAAAAAGiaIDAAAAAAAAAAAAAA0TBAZAAAAAAAAAAAAAGiYIDIAAAAAAAAAAAAA0DBBZAAAAAAAAAAAAACgYYLIAAAAAAAAAAAAAEDDBJEBAAAAAAAAAAAAgIYJIgMAAAAAAAAAAAAADRNEBgAAAAAAAAAAAAAaJogMAAAAAAAAAAAAADRMEBkAAAAAAAAAAAAAaJggMgAAAAAAAAAAAADQMEFkAAAAAAAAAAAAAKBhgsgAAAAAAAAAAAAAQMMEkQEAAAAAAAAAAACAhgkiAwAAAAAAAAAAAAANE0QGAAAAAAAAAAAAABomiAwAAAAAAAAAAAAANEwQGQAAAAAAAAAAAABomCAyAAAAAAAAAAAAANAwQWQAAAAAAAAAAAAAoGGCyAAAAAAAAAAAAABAw5qe6At2d3fnqquumvh+4cKFaW1tfaKnAQAAAAAAAA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-12 21:44:08 +08:00
"text/plain": [
"<Figure size 3600x3600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"import networkx as nx\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rcParams['font.sans-serif'] = 'SimHei'\n",
"\n",
"BomNodes = pd.read_csv('BomNodes.csv', index_col=0)\n",
"BomNodes.set_index('Code', inplace=True)\n",
"BomCateNet = pd.read_csv('BomCateNet.csv', index_col=0)\n",
"BomCateNet.fillna(0, inplace=True)\n",
"\n",
"G = nx.from_pandas_adjacency(BomCateNet, create_using=nx.MultiDiGraph())\n",
"\n",
"labels_dict = {}\n",
"for code in G.nodes:\n",
" labels_dict[code] = BomNodes.loc[code].to_dict()\n",
"nx.set_node_attributes(G, labels_dict)\n",
"\n",
"pos = nx.nx_agraph.graphviz_layout(G, prog=\"twopi\", args=\"\")\n",
"node_labels = nx.get_node_attributes(G, 'Name')\n",
"plt.figure(figsize=(12, 12), dpi=300)\n",
"nx.draw_networkx_nodes(G, pos)\n",
"nx.draw_networkx_edges(G, pos)\n",
"nx.draw_networkx_labels(G, pos, labels = node_labels, font_size=6)\n",
"plt.show()\n"
]
},
2023-02-13 20:49:33 +08:00
{
"cell_type": "code",
2023-02-25 20:14:53 +08:00
"execution_count": 2,
2023-02-13 20:49:33 +08:00
"metadata": {},
"outputs": [
{
"data": {
2023-02-25 20:14:53 +08:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAACyIAAAsQCAYAAABS037aAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdebidZWEu7metPe+dZO+MJIQwCciMiKIgoDhrHavVWmvLqcdTT61V69j253Dac1pFW6dWW6sWR9SCKCBQFChzmEkIkDCGzHP2PK7h98faWckmCbAUAeW+rytX1v6G932/bw25rs2zH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AAAAAEDDBJEBAAAAAAAAAAAAgIYJIgMAAAAAAAAAAAAADRNEBgAAAAAAAAAAAAAaJogMAAAAAAAAAAAAADRMEBkAAAAAAAAAAAAAaJggMgAAAAAAAAAAAADQMEFkAAAAAAAAAAAAAKBhgsgAAAAAAAAAAAAAQMMEkQEAAAAAAAAAAACAhgkiAwAAAAAAAAAAAAANE0QGAAAAAAAAAAAAABomiAwAAAAAAAAAAAAANEwQGQAAAAAAAAAAAABomCAyAAAAAAAAAAAAANAwQWQAAAAAAAAAAAAAoGGCyAAAAAAAAAAAAABAwwSRAQAAAAAAAAAAAICGCSIDAAAAAAAAAAAAAA0TRAYAAAAAAAAAAAAAGiaIDAAAAAAAAAAAAAA0TBAZAAAAAAAAAAAAAGiYIDIAAAAAAAAAAAAA0DBBZAAAAAAAAAAAAACgYYLIAAAAAAAAAAAAAEDDBJEBAAAAAAAAAAAAgIYJIgMAAAAAAAAAAAAADRNEBgAAAAAAAAAAAAAaJogMAAAAAAAAAAAAADRMEBkAAAAAAAAAAAAAaJggMgAAAAAAAAAAAAD
2023-02-13 20:49:33 +08:00
"text/plain": [
"<Figure size 3600x3600 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import pandas as pd\n",
"import networkx as nx\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.rcParams['font.sans-serif'] = 'SimHei'\n",
"\n",
"BomNodes = pd.read_csv('BomNodes.csv', index_col=0)\n",
"BomNodes.set_index('Code', inplace=True)\n",
"BomCateNet = pd.read_csv('BomCateNet.csv', index_col=0)\n",
"BomCateNet.fillna(0, inplace=True)\n",
"\n",
2023-02-25 20:14:53 +08:00
"G = nx.from_pandas_adjacency(BomCateNet.T, create_using=nx.MultiDiGraph())\n",
2023-02-13 20:49:33 +08:00
"\n",
2023-02-17 12:03:47 +08:00
"# # Amending Network\n",
"# G.remove_node(\"1\")\n",
"# list_added_edges = [(\"2\",\"1.1\"), (\"2\",\"1.2\"), (\"2\",\"1.3\"), (\"2\",\"1.4\"), (\"1.3\",\"2.1.4\"), (\"1.2\",\"1.4.3\")]\n",
"# G.add_edges_from(list_added_edges)\n",
2023-02-13 20:49:33 +08:00
"\n",
"labels_dict = {}\n",
"for code in G.nodes:\n",
" labels_dict[code] = BomNodes.loc[code].to_dict()\n",
"nx.set_node_attributes(G, labels_dict)\n",
"\n",
"pos = nx.nx_agraph.graphviz_layout(G, prog=\"twopi\", args=\"\")\n",
"node_labels = nx.get_node_attributes(G, 'Name')\n",
"temp = {}\n",
"for key, value in node_labels.items():\n",
" temp[key] = key + \" \"+ value\n",
"node_labels = temp\n",
"\n",
"plt.figure(figsize=(12, 12), dpi=300)\n",
"nx.draw_networkx_nodes(G, pos)\n",
"nx.draw_networkx_edges(G, pos)\n",
"nx.draw_networkx_labels(G, pos, labels = node_labels, font_size=6)\n",
"plt.show()\n"
]
},
2023-02-12 21:44:08 +08:00
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.8.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "bcdafc093860683ffb58d6956591562b7f8ed5d58147d17d71a5d4d6605a08df"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}