0

PYSPARK: how to visualize a GraphFrame?

This is a link to a question. I just need to add the labels(both the node names in vertices and relationship,ie, friend or follow in edges). How can I do so?

Harshal
  • 55
  • 7

1 Answers1

0

I had the same challenge and the only way I was able to solve this for spark graphframes was using the igraph module for plotting.

# 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)
Alex Ortner
  • 1,097
  • 8
  • 24