From a26b5baa34e18dc11b7e8238f66359c9a921a5a4 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 12 Feb 2023 22:19:13 +0800 Subject: [PATCH] requirement.txt --- LoadNetworkx_20230210-1.ipynb | 2 +- LoadNetworkx_20230210-1.py | 28 ++++++++++++++++++++++++++++ requirements.txt | 9 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 LoadNetworkx_20230210-1.py create mode 100644 requirements.txt diff --git a/LoadNetworkx_20230210-1.ipynb b/LoadNetworkx_20230210-1.ipynb index e16de0e..f4ec08a 100644 --- a/LoadNetworkx_20230210-1.ipynb +++ b/LoadNetworkx_20230210-1.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { diff --git a/LoadNetworkx_20230210-1.py b/LoadNetworkx_20230210-1.py new file mode 100644 index 0000000..ee1c2e9 --- /dev/null +++ b/LoadNetworkx_20230210-1.py @@ -0,0 +1,28 @@ +# %% +import pandas as pd +import networkx as nx +import matplotlib.pyplot as plt + +plt.rcParams['font.sans-serif'] = 'SimHei' + +BomNodes = pd.read_csv('BomNodes.csv', index_col=0) +BomNodes.set_index('Code', inplace=True) +BomCateNet = pd.read_csv('BomCateNet.csv', index_col=0) +BomCateNet.fillna(0, inplace=True) + +G = nx.from_pandas_adjacency(BomCateNet, create_using=nx.MultiDiGraph()) + +labels_dict = {} +for code in G.nodes: + labels_dict[code] = BomNodes.loc[code].to_dict() +nx.set_node_attributes(G, labels_dict) + +pos = nx.nx_agraph.graphviz_layout(G, prog="twopi", args="") +node_labels = nx.get_node_attributes(G, 'Name') +plt.figure(figsize=(12, 12), dpi=300) +nx.draw_networkx_nodes(G, pos) +nx.draw_networkx_edges(G, pos) +nx.draw_networkx_labels(G, pos, labels=node_labels, font_size=6) +plt.show() + +# %% diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..91f2ba8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,9 @@ +agentpy==0.1.5 +matplotlib==3.3.4 +matplotlib-inline==0.1.6 +networkx==2.5 +numpy==1.20.3 +numpydoc==1.1.0 +pandas==1.4.1 +pandas-stubs==1.2.0.39 +pygraphviz==1.9