-1

我使用 GraphFrame 创建了一个图表

g = GraphFrame (vertices, edges)

除了使用 GraphFrame 提供的查询和属性分析图形之外,我还想可视化图形以在演示文稿中使用。

您是否知道以简单的方式允许这种可视化的任何工具/库/API/代码?

4

2 回答 2

2

这不是一个简单的方法,但您可以使用 python-igraph 库,https: //igraph.org/ 。我从 R 中使用它,但 python 应该是相似的。请参见下面的简单示例。所有该工具的主要问题是,您应该仔细选择要绘制的小子图。

安装它:

#>pip install python-igraph

最简单的可视化:

g = GraphFrame (vertices, edges)
from igraph import *
ig = Graph.TupleList(g.edges.collect(), directed=True)
plot(ig)
于 2019-02-11T14:24:43.887 回答
1

另一种方法是使用图形模块 networkx 中的绘图功能

import networkx as nx
from graphframes import GraphFrame

def PlotGraph(edge_list):
    Gplot=nx.Graph()
    for row in edge_list.select('src','dst').take(1000):
        Gplot.add_edge(row['src'],row['dst'])

    plt.subplot(121)
    nx.draw(Gplot)


spark = SparkSession \
    .builder \
    .appName("PlotAPp") \
    .getOrCreate()

sqlContext = SQLContext(spark)

vertices = sqlContext.createDataFrame([
  ("a", "Alice", 34),
  ("b", "Bob", 36),
  ("c", "Charlie", 30),
  ("d", "David", 29),
  ("e", "Esther", 32),
("e1", "Esther2", 32),
  ("f", "Fanny", 36),
  ("g", "Gabby", 60),
    ("h", "Mark", 61),
    ("i", "Gunter", 62),
    ("j", "Marit", 63)], ["id", "name", "age"])

edges = sqlContext.createDataFrame([
  ("a", "b", "friend"),
  ("b", "a", "follow"),
  ("c", "a", "follow"),
  ("c", "f", "follow"),
  ("g", "h", "follow"),
  ("h", "i", "friend"),
  ("h", "j", "friend"),
  ("j", "h", "friend"),
    ("e", "e1", "friend")
], ["src", "dst", "relationship"])

g = GraphFrame(vertices, edges)
PlotGraph(g.edges)

另请参阅PYSPARK:如何可视化 GraphFrame?

于 2019-09-04T12:56:53.170 回答