質問編集履歴
1
具体化
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Networkx の 座標表示
|
test
CHANGED
@@ -1 +1,129 @@
|
|
1
|
+
```python
|
2
|
+
|
3
|
+
df_tr.head()
|
4
|
+
|
5
|
+
```
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
||F1|F2|F3|F4|
|
10
|
+
|
11
|
+
|---|---|---|---|
|
12
|
+
|
13
|
+
|工場|||||
|
14
|
+
|
15
|
+
|W1|15|15|0|5|
|
16
|
+
|
17
|
+
|W2|5|0|30|5|
|
18
|
+
|
19
|
+
|W3|10|15|2|15|
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
```python
|
24
|
+
|
25
|
+
df_pos.head()
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
||W1|W2|W3|F1|F2|F3|F4|
|
32
|
+
|
33
|
+
|---|--
|
34
|
+
|
35
|
+
|0|0|0|0|4.0|4.0|4.0|4.0|
|
36
|
+
|
37
|
+
|1|1|2|3|0.5|1.5|2.5|3.5|
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```python
|
46
|
+
|
47
|
+
#グラフィックオブジェクトの作成
|
48
|
+
|
49
|
+
G = nx.Graph()
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
#頂点の設定
|
54
|
+
|
55
|
+
for i in range(len(df_pos.columns)):
|
56
|
+
|
57
|
+
G.add_node(df_pos.columns[i])
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
#辺の設定&エッジの重みのリスト化
|
62
|
+
|
63
|
+
num_pre = 0
|
64
|
+
|
65
|
+
edge_weights = []
|
66
|
+
|
67
|
+
size = 0.1
|
68
|
+
|
69
|
+
for i in range(len(df_pos.columns)): #i=[0,1,2,3,4,5,6,]
|
70
|
+
|
71
|
+
for j in range(len(df_pos.columns)): #j=[0,1,2,3,4,5,6]
|
72
|
+
|
73
|
+
if not(i==j):
|
74
|
+
|
75
|
+
#辺の追加
|
76
|
+
|
77
|
+
G.add_edge(df_pos.columns[i],df_pos.columns[j])
|
78
|
+
|
79
|
+
#エッジの重みの追加
|
80
|
+
|
81
|
+
if num_pre<len(G.edges):
|
82
|
+
|
83
|
+
num_pre = len(G.edges)
|
84
|
+
|
85
|
+
weight = 0
|
86
|
+
|
87
|
+
if (df_pos.columns[i] in df_tr.columns)and(df_pos.columns[j] in df_tr.index):
|
88
|
+
|
89
|
+
if df_tr[df_pos.columns[i]][df_pos.columns[j]]:
|
90
|
+
|
91
|
+
weight = df_tr[df_pos.columns[i]][df_pos.columns[j]]*size
|
92
|
+
|
93
|
+
elif(df_pos.columns[j] in df_tr.columns)and(df_pos.columns[i] in df_tr.index):
|
94
|
+
|
95
|
+
if df_tr[df_pos.columns[j]][df_pos.columns[i]]:
|
96
|
+
|
97
|
+
weight = df_tr[df_pos.columns[j]][df_pos.columns[i]]*size
|
98
|
+
|
99
|
+
edge_weights.append(weight)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
#座標の設定
|
104
|
+
|
105
|
+
pos = {}
|
106
|
+
|
107
|
+
for i in range(len(df_pos.columns)):
|
108
|
+
|
109
|
+
node = df_pos.columns[i]
|
110
|
+
|
111
|
+
pos[node] = (df_pos[node][0],df_pos[node][1])
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
#描画
|
116
|
+
|
117
|
+
nx.draw(G,pos,with_labels = True ,font_size = 16,node_size = 1000,node_color = 'k',font_color = 'w', width = edge_weights )
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
#表示
|
122
|
+
|
123
|
+
plt.show()
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
この出力結果を
|
128
|
+
|
1
|
-
teratail
|
129
|
+
teratail上に表示するにはどのように記述すれば良いのでしょうか?
|