January 2, 2019

Python networkx nxviz package

networkx, nxviz packages in Python

import networkx as nx
g=nx.Graph() -- Undirected Graph
d=nx.DiGraph() -- Directed Graph
mg=nx.MultiGraph()
md=nx.MultiDiGraph()
type(g)
>>> G.add_node("spam")
>>> G.add_edge(1,2)

g.add_nodes_from([1,2,3])
g.add_nodes_from(nums, bipartite='cust')
g.nodes()
g.nodes(data=True) -- with metadata
type(T.nodes())
noi = [n for n, d in T.nodes(data=True) if d['occupation'] == 'scientist']
g.node[1]['label'] = 'blue'
  g.add_edge(1,2)
g.edges()
T.edge[1][10]
T.edge[1][8]['weight'] = 1
T.edges(data=True) -- with metadata
T.edges(data=True)[2]
T.edges(data=True)[-1]
eoi = [(u, v) for u, v, d in T.edges(data=True) if d['date'] < date(2017, 1, 1)]

len(T)
g.number_of_selfloops()
nx.draw(g)
>>> nx.draw_spectral(G)
>>> nx.draw_circular(G)
nx.to_numpy_matrix(G)
nx.from_numpy_matrix(A)
nx.from_numpy_matrix(A, create_using=nx.DiGraph)
g.neighbors('user1')
dcs = nx.degree_centrality(G)
G.node[n]['centrality'] = dcs[n]
nx.bipartite.degree_centrality(g, cust_nodes)
if G.node[n]['bipartite'] == partition: print(n)
assert G.node[node1]['bipartite'] == G.node[node2]['bipartite']

>>> nx.write_gml(red,"path.to.file")
>>> mygraph=nx.read_gml("path.to.file")

import nxviz as nv
from nxviz import CircosPlot
ap=nv.ArcPlot(g)
a2 = ArcPlot(T,node_order='category',node_color='category')
m = nv.MatrixPlot(T)
c = CircosPlot(T)
c = CircosPlot(G,node_color='bipartite',node_grouping='bipartite',node_order='centrality')
ap.draw()

Related Python Articles: sklearn skimage packages in Python     File Handling in Python


No comments:

Post a Comment