In [1]:
import graphistry
#graphistry.register(key='MY_KEY', server='labs.graphistry.com') #https://www.graphistry.com/api-request
import networkx as nx
import pandas as pd
In [2]:
num_nodes = 1000
G=nx.Graph()
G.add_nodes_from(range(num_nodes))
Edges = [(x, (x * 2) % (num_nodes/5)) for x in range(num_nodes)] + [(x, (x + 1) % 20) for x in range(20)]
G.add_edges_from(Edges)
G
Out[2]:
In [3]:
%time
pos=nx.fruchterman_reingold_layout(G)
pos[0]
Out[3]:
In [4]:
def pos2df (pos):
nodes = pd.DataFrame({'key': pos.keys(), 'pos_0': [pos[k][0] for k in pos.keys()], 'pos_1': [pos[k][1] for k in pos.keys()]})
nodes.columns = ['key', 'x', 'y']
return nodes
In [5]:
nodes = pos2df(pos)
nodes[:3]
Out[5]:
In [6]:
edges = pd.DataFrame(Edges)
edges.columns = ['src', 'dst']
edges[:3]
Out[6]:
In [7]:
g = graphistry.nodes(nodes).edges(edges).bind(source='src', destination='dst', node='key')
g.plot()
Out[7]:
In [8]:
g2 = g.settings(url_params={'play':0})
g.plot()
Out[8]:
In [9]:
pos2=nx.circular_layout(G, scale=100)
nodes2 = pos2df(pos2)
g2.nodes(nodes2).plot()
Out[9]:
In [ ]: