You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用igraph在Dash中构建3D加权网络时权重不影响边长度问题

问题:igraph加权3D网络布局中权重未影响边长度

我尝试使用igraph在Dash中创建加权3D网络,尽管图已被识别为加权图(is_weighted(G)返回True),但权重并未对边的长度产生影响。

示例输入

d = {'nodes':[{'name': 'CHEMBL10', 'group': 0}, {'name': 'CSNK1D', 'group': 1}, {'name': 'GAK', 'group': 1}, {'name': 'GCGR', 'group': 1}, {'name': 'MAPK10', 'group': 1}, {'name': 'MAPK14', 'group': 1}, {'name': 'RIPK2', 'group': 1}], 'links':[{'source': 0, 'target': 1, 'value': 99.74870362983646}, {'source': 0, 'target': 2, 'value': 35.12963701635421}, {'source': 0, 'target': 3, 'value': 100.0}, {'source': 0, 'target': 4, 'value': 57.10011966493818}, {'source': 0, 'target': 5, 'value': 10.0}, {'source': 0, 'target': 6, 'value': 53.0793777423215}]}

示例代码

import igraph as ig

N=len(d['nodes'])
L=len(d['links'])
Edges=[(d['links'][k]['source'], d['links'][k]['target'], d['links'][k]['value']) for k in range(L)]
G=ig.Graph.TupleList(Edges, directed=False, weights=True)
layt=G.layout('kk_3d', dim=3)
labels=[]
group=[]

for node in zip(d['nodes']):
        labels.append(node['name'])
        group.append(node['group'])

Xn=[layt[k][0] for k in range(N)]
Yn=[layt[k][1] for k in range(N)]
Zn=[layt[k][2] for k in range(N)]
Xe=[]
Ye=[]
Ze=[]
for e in Edges:
    Xe+=[layt[e[0]][0],layt[e[1]][0], None]
    Ye+=[layt[e[0]][1],layt[e[1]][1], None]
    Ze+=[layt[e[0]][2],layt[e[1]][2], None]

trace1=go.Scatter3d(x=Xe, y=Ye, z=Ze, mode='lines', line=dict(color='rgb(125,125,125)', width=2),hoverinfo='text', text=edge_weights)
trace2=go.Scatter3d(x=Xn, y=Yn, z=Zn, mode='markers', name='actors',marker=dict(symbol='circle', size=6, color=group, colorscale='Viridis',line=dict(color='rgb(50,50,50)', width=1)), text=labels, hoverinfo='text')

axis=dict(range=[-3,3], showbackground=True, showline=True, zeroline=True, showgrid=True, showticklabels=True, title='')

layout = go.Layout(autosize=False,
             width=1450,
             height=1000,
             plot_bgcolor='rgba(0,0,0,0)',
             paper_bgcolor='rgba(0,0,0,0)',
             margin=dict(t=20, b=20, l=20, r=20, pad=20),
             showlegend=False,
             scene=dict(
                 xaxis=dict(axis),
                 yaxis=dict(axis),
                 zaxis=dict(axis),
                 aspectratio=go.layout.scene.Aspectratio(x=1.2, y=1.2, z=1.2),
            ))
data=[trace1, trace2]
fig=go.Figure(data=data, layout=layout)

我已尝试多种方法,比如更换布局算法、在创建边后添加权重、改用G=ig.Graph.DataFrame(df, directed=False, use_vids=False)创建图,但边的长度始终一致(XYZ坐标完全相同)。

请问有什么解决思路?


内容的提问来源于stack exchange,提问作者Paschalis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 16:32:51