{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1425232 characters]",
      "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"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 1527952 characters]",
      "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.T, create_using=nx.MultiDiGraph())\n",
    "\n",
    "# # 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",
    "\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"
   ]
  },
  {
   "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
}
