我有数百个列表(每个列表对应1个人)。每个列表包含100个字符串,这是该人的100个朋友。
我想根据他们拥有的普通朋友的数量,对这个人网络进行3D可视化。考虑到任何2个列表,它们具有的字符串越多,它们在这个3D图形中应该越接近一起出现。我希望将每个列表显示为3D图形上的点,而点之间没有节点/连接。
为简洁起见,我这里只包括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']
答案 0 :(得分:6)
Gephi设置步骤:
Gephi
,然后启动它Workspace1
Graph Streaming
插件Streaming
标签中显示配置服务器以使用http
和端口8080
Python步骤:
gephistreamer
包(pip install gephistreamer
)将以下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)
使用命令python friends.py
运行它
您应该看到所有节点都出现了。有很多方法可以让它看起来更好看,我在这里使用Force Atlas
布局,你可以看到我在左边使用的参数。
有些说明:
T
来显示或消失标签。Window/Data Table
。这会让你开始(正如你的要求),但对于你的特定问题:
使用 Anaconda 4.4.1 和 Python 3.5.2 以及 Gephi 0.9.1 在 Windows 10 上运行强>