NetworkX

NetworkX#

NetworkX 是一个早期的图操作库,具有多种算法和布局。

[1]:
import graphistry

# To specify Graphistry account & server, use:
# graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com')
# For more options, see https://github.com/graphistry/pygraphistry#configure

import networkx as nx
import pandas as pd
[2]:
G = nx.Graph()
G.add_nodes_from([
    (1, {"v": "one"}),
    (2, {"v": "two"}),
    (3, {"v": "three"}),
    (4, {"v": "four"}),
    (7, {"v": "seven"}),
    (8, {"v": "eight"})])
G.add_edges_from([
    [2,3],
    [3,4],
    [7,8]])
graphistry.bind(source='src', destination='dst', node='nodeid').plot(G)
[2]:

在操作图形时,这种形式更加方便,因为你可以使用PyGraphistry方法进行过滤、算法增强、GFQL查询等任务:

[ ]:
g = graphistry.bind().from_networkx(G)

assert isinstance(g._edges, pd.DataFrame)
assert isinstance(g._nodes, pd.DataFrame)

g._edges