質問編集履歴
4
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,6 @@
|
|
54
54
|
### 試したこと
|
55
55
|
|
56
56
|
edges中身を表示させると、labelの値は反映されていたが、HTML上での表示はされていない
|
57
|
-
edges['label']を文字列型に変換しても表示されませんでした
|
58
57
|
|
59
58
|
ネットワーク図の描画プログラムは初めてなので細かい部分は理解が足りていない可能性があります
|
60
59
|
|
3
新たに試したことの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,8 +54,11 @@
|
|
54
54
|
### 試したこと
|
55
55
|
|
56
56
|
edges中身を表示させると、labelの値は反映されていたが、HTML上での表示はされていない
|
57
|
+
edges['label']を文字列型に変換しても表示されませんでした
|
57
58
|
|
58
59
|
ネットワーク図の描画プログラムは初めてなので細かい部分は理解が足りていない可能性があります
|
60
|
+
|
61
|
+
|
59
62
|
|
60
63
|
### 補足情報(FW/ツールのバージョンなど)
|
61
64
|
|
2
サンプルファイル追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,6 +40,17 @@
|
|
40
40
|
# display(HTML(test+".html"))
|
41
41
|
```
|
42
42
|
|
43
|
+
```test.csv
|
44
|
+
objective,column1,column2,column3
|
45
|
+
10,5,6,7
|
46
|
+
9,6,7,8
|
47
|
+
8,6,6,6
|
48
|
+
```
|
49
|
+
### 結果
|
50
|
+
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-10-04/70b30810-9367-43fa-95b8-28268711b41d.png)
|
51
|
+
|
52
|
+
ここに加えて、各エッジに相関係数を表示させたい
|
53
|
+
|
43
54
|
### 試したこと
|
44
55
|
|
45
56
|
edges中身を表示させると、labelの値は反映されていたが、HTML上での表示はされていない
|
1
内容の省略
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,13 +16,11 @@
|
|
16
16
|
def graph(test):
|
17
17
|
df = pd.read_csv(test+".csv", sep=',')
|
18
18
|
df_corr = df.corr()
|
19
|
+
threshold = 0.4
|
19
20
|
mask_df = df_corr.mask(np.triu(np.ones(df_corr.shape)).astype(bool), None) # 「右上の三角行列」にマスクをして、Noneに置き換える
|
20
21
|
|
21
22
|
# edges data frame
|
22
23
|
edges = mask_df.stack().reset_index().rename(columns={"level_0":"source", "level_1":"target", 0:"weight"})
|
23
|
-
edges = edges.loc[abs(edges['weight'])> threshold] # 該当のノードのみ出したい場合コメントアウト外す
|
24
|
-
edges['width'] = edges['weight'].apply(lambda x: abs(x) * edge_width if abs(x) > threshold else 0) # weightに応じて、エッジの太さを変更
|
25
|
-
edges['color'] = edges['weight'].apply(lambda x: '#33A5CC' if abs(x) >threshold else '#BD4141') # edgeの色
|
26
24
|
edges['label'] = edges['weight'].apply(lambda x: np.round(x,2) if abs(x) > threshold else '')
|
27
25
|
|
28
26
|
#しきい値以上の接続に限定
|
@@ -35,40 +33,16 @@
|
|
35
33
|
|
36
34
|
# グラフ構造
|
37
35
|
nt.repulsion(node_distance=300) #default 300
|
38
|
-
|
39
|
-
# ノードのレイアウト
|
40
|
-
neighbor_map = nt.get_adj_list()
|
41
|
-
for n in nt.nodes:
|
42
|
-
n['font'] = {'size':20, 'strokeWidth':6}
|
43
|
-
n['size'] = 15 # shapeの内部にラベルがないノード形状のサイズ
|
44
|
-
|
45
|
-
threshold2 = 0.7
|
46
|
-
threshold3 = -1 * threshold2
|
47
|
-
|
48
|
-
# エッジのレイアウト
|
49
|
-
for e in nt.edges:
|
50
|
-
if e['weight'] > threshold2:
|
51
|
-
e['font'] = {'size':30, 'strokeWidth':10, 'color': '#33A5CC'}
|
52
|
-
# strokeWidth: weightの背景範囲
|
53
|
-
e['color'] = '#cc3333'
|
54
|
-
|
55
|
-
else:
|
56
|
-
e['font'] = {'size':30, 'strokeWidth':10, 'color': '#BD4141'}
|
57
|
-
if e['weight'] < threshold3:
|
58
|
-
e['color'] = '#33cc45'
|
59
36
|
|
60
37
|
nt.show_buttons(filter_=['physics','nodes'])
|
61
38
|
|
62
39
|
nt.show(test+".html")
|
63
|
-
# display(HTML(s
|
40
|
+
# display(HTML(test+".html"))
|
64
41
|
```
|
65
42
|
|
66
43
|
### 試したこと
|
67
44
|
|
68
|
-
edgesやeの中身を表示させた
|
69
|
-
どちらもlabelが表示されていたが
|
70
|
-
edge
|
45
|
+
edges中身を表示させると、labelの値は反映されていたが、HTML上での表示はされていない
|
71
|
-
eのlabelは小数点以下2桁に丸まっておらず、このあたりで問題が起こっていると考えています
|
72
46
|
|
73
47
|
ネットワーク図の描画プログラムは初めてなので細かい部分は理解が足りていない可能性があります
|
74
48
|
|