[英]Python friends network visualization
I have hundreds of lists (each list corresponds to 1 person). 我有数百个列表(每个列表对应1个人)。 Each list contains 100 strings, which are the 100 friends of that person. 每个列表包含100个字符串,这是该人的100个朋友。
I want to 3D visualize this people network based on the number of common friends they have. 我想根据他们拥有的普通朋友的数量,对这个人网络进行3D可视化。 Considering any 2 lists, the more same strings they have, the closer they should appear together in this 3D graph. 考虑到任何2个列表,它们具有的字符串越多,它们在这个3D图形中应该越接近一起出现。 I wanted to show each list as a dot on the 3D graph without nodes/connections between the dots. 我想将每个列表显示为3D图形上的点,而点之间没有节点/连接。
For brevity, I have included only 3 people here. 为简洁起见,我在这里只包括3个人。
person1 = ['mike', 'alex', 'arker','locke','dave','david','ross','rachel','anna','ann','darl','carl','karle']
person2 = ['mika', 'adlex', 'parker','ocke','ave','david','rosse','rachel','anna','ann','darla','carla','karle']
person3 = ['mika', 'alex', 'parker','ocke','ave','david','rosse','ross','anna','ann','darla','carla','karle', 'sasha', 'daria']
Gephi Setup steps: Gephi设置步骤:
Gephi
and then start it 安装Gephi
然后启动它 Workspace1
确保当前工作空间是Workspace1
Graph Streaming
plugin 启用Graph Streaming
插件 Streaming
tab that then appears configure server to use http
and port 8080
然后在Streaming
选项卡中显示configure server以使用http
和端口8080
Python steps: Python步骤:
gephistreamer
package ( pip install gephistreamer
) 安装gephistreamer
包( pip install gephistreamer
) Copy the following python cod to something like friends.py
: 将以下python cod复制到friends.py
东西:
from gephistreamer import graph
from gephistreamer import streamer
import random as rn
stream = streamer.Streamer(streamer.GephiWS(hostname="localhost",port=8080,workspace="workspace1"))
szfak = 100 # this scales up everything - somehow it is needed
cdfak = 3000
nodedict = {}
def addfnode(fname):
# grab the node out of the dictionary if it is there, otherwise make a newone
if (fname in nodedict):
nnode = nodedict[fname]
else:
nnode = graph.Node(fname,size=szfak,x=cdfak*rn.random(),y=cdfak*rn.random(),color="#8080ff",type="f")
nodedict[fname] = nnode # new node into the dictionary
return nnode
def addnodes(pname,fnodenamelist):
pnode = graph.Node(pname,size=szfak,x=cdfak*rn.random(),y=cdfak*rn.random(),color="#ff8080",type="p")
stream.add_node(pnode)
for fname in fnodenamelist:
print(pname+"-"+fname)
fnode = addfnode(fname)
stream.add_node(fnode)
pfedge = graph.Edge(pnode,fnode,weight=rn.random())
stream.add_edge(pfedge)
person1friends = ['mike','alex','arker','locke','dave','david','ross','rachel','anna','ann','darl','carl','karle']
person2friends = ['mika','adlex','parker','ocke','ave','david','rosse','rachel','anna','ann','darla','carla','karle']
person3friends = ['mika','alex','parker','ocke','ave','david','rosse','ross','anna','ann','darla','carla','karle','sasha','daria']
addnodes("p1",person1friends)
addnodes("p2",person2friends)
addnodes("p3",person3friends)
Run it with the command python friends.py
You should see all the nodes appear. 使用命令python friends.py
运行它您应该看到所有节点都出现。 There are then lots of ways you can lay it out to make it look better, I am using the Force Atlas
layouter here and you can see the parameters I am using on the left. 有很多方法可以让它看起来更好看,我在这里使用Force Atlas
layouter,你可以看到我在左边使用的参数。
Some notes: 一些说明:
T
on the bottom status/control bar. 您可以通过单击底部状态/控制栏上的T
来显示或消失标签。 Window/Data Table
. 通过打开“ Window/Data Table
查看节点和边缘中的Window/Data Table
。 This will get you started (as you asked), but for your particular problem: 这将使您开始(如您所知),但针对您的特定问题:
This is running on Windows 10 using Anaconda 4.4.1 and Python 3.5.2 and Gephi 0.9.1 . 这是在Windows 10上使用Anaconda 4.4.1和Python 3.5.2以及Gephi 0.9.1运行的 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.