Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 网络分析,以绘图方式显示悬停和文本信息_Python_Pandas_Networking_Plotly_Networkx - Fatal编程技术网

Python 网络分析,以绘图方式显示悬停和文本信息

Python 网络分析,以绘图方式显示悬停和文本信息,python,pandas,networking,plotly,networkx,Python,Pandas,Networking,Plotly,Networkx,我正在尝试使用网络和绘图来可视化网络分析图表。我有两个数据集: 边缘列表,包含所有边缘信息;2.具有所有节点信息的节点列表。 示例的EdgeLst(非完整数据): 节点列表示例(非完整数据): 我只可视化了基本的网络图,如下面的代码所示,但只有位置和简单的信息。我希望在鼠标移动到每个节点时显示网络图中的其他列,显示数据集中的其他悬停文本/信息。不幸的是,我不知道如何在网络中的dict、list或tuple中附加或添加其他字段。如果有人能帮忙,我真的很感激! 以下是我当前的代码: impo

我正在尝试使用网络和绘图来可视化网络分析图表。我有两个数据集:

  • 边缘列表,包含所有边缘信息;2.具有所有节点信息的节点列表。 示例的EdgeLst(非完整数据):

  • 节点列表示例(非完整数据):

  • 我只可视化了基本的网络图,如下面的代码所示,但只有位置和简单的信息。我希望在鼠标移动到每个节点时显示网络图中的其他列,显示数据集中的其他悬停文本/信息。不幸的是,我不知道如何在网络中的dict、list或tuple中附加或添加其他字段。如果有人能帮忙,我真的很感激! 以下是我当前的代码:

    import plotly.graph_objects as go
    import networkx as nx
    import pandas as pd
    
    
    node_list = pd.read_csv("nodelist1.csv")
    edge_list = pd.read_csv("edgelist1.csv")
    
    nodes = list(node_list['node'])
    
    edge_list['edge_conn'] = edge_list[['tail', 'head']].apply(tuple, axis=1)
    edges = list(edge_list['edge_conn'])
    
    G = nx.Graph()
    
    G.add_nodes_from(nodes)
    G.add_edges_from(edges)
    
    pos = nx.layout.spring_layout(G)
    
      
    edge_x = []
    edge_y = []
    
    for loc_idx in pos:
      # print (loc_idx, pos[loc_idx])
      x0, y0 = pos[loc_idx]
      edge_x.append(x0)
      edge_y.append(y0)
    
    edge_trace = go.Scatter(
        x=edge_x, y=edge_y,
        line=dict(width=0.5, color='#888'),
        hoverinfo='none',
        mode='lines')
    
    node_x = []
    node_y = []
    
    for node_loc in pos:
      x, y = pos[node_loc]
      node_x.append(x)
      node_y.append(y)
    
    node_trace = go.Scatter(
        x=node_x,
        y=node_y,
        mode='markers',
        marker=dict(
            showscale=True,
            colorscale='YlGnBu',
            reversescale=True,
            color=[],
            size=10,
            colorbar=dict(
                thickness=15,
                title='Node Connections',
                xanchor='left',
                titleside='right'
            ),
        line_width=2
    ))
    node_adjacencies = []
    node_text = []
    for node, adjacencies in enumerate(G.adjacency()):
        node_adjacencies.append(len(adjacencies[1]))
        node_text.append('# of connections: '+str(len(adjacencies[1])))
    
    node_trace.marker.color = node_adjacencies
    node_trace.text = node_text
    
    fig = go.Figure(data=[edge_trace, node_trace],
                 layout=go.Layout(
                    title='<br>Network graph made with Python',
                    titlefont_size=16,
                    showlegend=False,
                    hovermode='closest',
                    margin=dict(b=20,l=5,r=5,t=40),
                    annotations=[ dict(
                        showarrow=False,
                        xref="paper", yref="paper",
                        x=0.005, y=-0.002 ) ],
                    xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
                    yaxis=dict(showgrid=False, zeroline=False, showticklabels=False))
                    )
    fig.show()
    
    导入plotly.graph\u对象
    将networkx导入为nx
    作为pd进口熊猫
    node\u list=pd.read\u csv(“nodelist1.csv”)
    edge\u list=pd.read\u csv(“edgelist1.csv”)
    节点=列表(节点列表['node'])
    边列表['edge\u conn']=边列表[['tail','head']]。应用(元组,axis=1)
    边缘=列表(边缘列表['edge\u conn'])
    G=nx.Graph()
    G.从(节点)添加节点
    G.从(边)添加边
    位置=nx布局。弹簧布局(G)
    边缘_x=[]
    边缘_y=[]
    对于位置中的loc_idx:
    #打印(loc_idx,位置[loc_idx])
    x0,y0=pos[loc_idx]
    边附加(x0)
    边y.追加(y0)
    边缘跟踪=开始分散(
    x=边x,y=边y,
    线条=笔迹(宽度=0.5,颜色='#888'),
    hoverinfo='none',
    模式(行)
    节点_x=[]
    节点_y=[]
    对于位置中的节点位置:
    x、 y=位置[节点位置]
    节点x.append(x)
    节点_y.追加(y)
    节点_trace=go.Scatter(
    x=节点x,
    y=节点y,
    mode='markers',
    记号笔(
    showscale=True,
    colorscale='YlGnBu',
    反向刻度=真,
    颜色=[],
    尺寸=10,
    色条(
    厚度=15,
    title='Node Connections',
    xanchor='left',
    标题旁边的“='right'
    ),
    线宽=2
    ))
    节点_邻接=[]
    节点_text=[]
    对于节点,枚举中的邻接(G.adjacency()):
    node_adjaccines.append(len(adjaccines[1]))
    node_text.append('#of connections:'+str(len(邻接[1]))
    node_trace.marker.color=节点_邻接
    node_trace.text=节点_text
    fig=go.Figure(数据=[边缘跟踪,节点跟踪],
    布局=go.layout(
    title=“
    用Python制作的网络图”, titlefont_尺寸=16, showlegend=False, hovermode='closest', 保证金=dict(b=20,l=5,r=5,t=40), 注释=[dict]( showarrow=False, xref=“纸张”,yref=“纸张”, x=0.005,y=-0.002)], xaxis=dict(showgrid=False,zeroline=False,showticklabels=False), yaxis=dict(showgrid=False,zeroline=False,showticklabels=False)) ) 图2(图3)
    你好,爱丽丝!我想你更愿意任何人回答你的问题,而不是重复你的问题。你可以在这方面提供帮助。请不要将数据样本作为图像共享。这意味着我们必须花时间输入您的数据,而不是找到答案。而是共享您的数据。