从Networkx中的图框打印标签

时间:2019-09-10 10:16:59

标签: python apache-spark networkx graphframes

PYSPARK: how to visualize a GraphFrame?

这是一个问题的链接。我只需要添加标签(节点名称在顶点和关系中,即朋友或边缘跟随)。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我面临着同样的挑战,对于火花图框架,解决此问题的唯一方法是使用igraph模块进行绘图。

# import the modules
import networkx as nx
from igraph import *
import cairocffi

# create your networkx graph object 
graph_list=[]
graph_list.append(['start','end',{'edge_label':'myLabel'}])
G=nx.MultiDiGraph()
G.add_edges_from(graph_list)

# then create the label lists
# you can either use the edge/vertices values as label or add custom labels as attributes

vertex_label=[str(e[0]) for e in graph.edges.data()]
edge_label=[int(e[2]['edge_label']) for e in graph.edges.data()]

ig = Graph.TupleList(graph.edges, directed=True)
plot(ig,vertex_label=vertex_label,edge_label=edge_label)