简体   繁体   English

Gephi - 带有彩色节点的 open.networkx

[英]Gephi - open networkx with colored nodes

I have a rather large.network (34594 nodes and 3897 edges).我有一个相当大的网络(34594 个节点和 3897 个边)。 I created a Networkx.network in Python and gave the nodes a color based on the label of the node.我在 Python 中创建了一个 Networkx.network,并根据节点的 label 为节点赋予颜色。 The label links the node to 5 countries based on the beginning letters. label 根据开头字母将节点链接到 5 个国家。 In Python, this all worked out fine, but for visualization purposes I exported the file (.gexf) to open it in Gephi.在 Python 中,一切正常,但出于可视化目的,我导出文件 (.gexf) 以在 Gephi 中打开它。 However, when I open it again, it does not have the colors anymore.但是,当我再次打开它时,它不再有 colors。 There is a plug-in (Give color to nodes), however, it seems that I have to change the color manually, node per node.有一个插件(给节点赋予颜色),但是,似乎我必须手动更改颜色,每个节点一个节点。 You can import a spreadsheet, which I initially wanted to do, and use as some type of look-up table.您可以导入我最初想做的电子表格,并将其用作某种类型的查找表。 However, this is not possible, and you can only import the nodes from there, but those are not linked to the.network.但是,这是不可能的,您只能从那里导入节点,但这些节点未链接到 .network。

Does anybody has any insights on how to solve this problem?有人对如何解决这个问题有任何见解吗?

Since you are using networkx , I will propose a very simple script that iterates all nodes and colors every node as blue .由于您使用的是networkx ,我将提出一个非常简单的脚本,它将所有节点和 colors 每个节点迭代为blue

import networkx as nx

# Construct a simple line graph
G = nx.path_graph(4)

for v in nx.nodes(G):
    # Set the viz attribute for each node
    G.nodes[v]["viz"] = {} 
    # Set the color to blue
    G.nodes[v]["viz"]["color"] = {"a":0, "r": 0, "g": 0, "b": 255}
     
# output a sample graph
nx.write_gexf(G, 'test.gexf')

The line G.nodes[v]["viz"] = {} , is required to add the viz dictionary to each node, and then we add the ARGB value of each node. G.nodes[v]["viz"] = {}行需要将viz字典添加到每个节点,然后我们添加每个节点的 ARGB 值。 In this example a=0 and RGB=(0,0,255) or, simply speaking, blue.在此示例a=0RGB=(0,0,255) ,或者简单地说,蓝色。

The script is based on networkx documentation , with some small changes.该脚本基于networkx 文档,有一些小改动。 Adding colors should also be possible with an adaptation of nx.setNodeAttibutes , as shown here .添加 colors 也应该可以通过调整nx.setNodeAttibutes来实现,如此处所示 It is just that the GEXF format, needs the viz attribute, and then the the corresponding color .只是GEXF格式,需要viz属性,然后是对应的color

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM