python网络绘图库networkx

http://blog.csdn.net/pipisorry/article/details/49839251

Networkx数据类型

Graph types

NetworkX provides data structures and methods for storing graphs.

All NetworkX graph classes allow (hashable) Python objects as nodes.and any Python object can be assigned as an edge attribute.

The choice of graph class depends on the structure of thegraph you want to represent.

使用哪种图形类

Graph Type NetworkX Class
Undirected Simple Graph
Directed Simple DiGraph
With Self-loops Graph, DiGraph
With Parallel edges MultiGraph, MultiDiGraph
  • Graph – Undirected graphs with self loops
    • Overview
    • Adding and removing nodes and edges
    • Iterating over nodes and edges
    • Information about graph structure
    • Making copies and subgraphs
  • DiGraph - Directed graphs with self loops
    • Overview
    • Adding and removing nodes and edges
    • Iterating over nodes and edges
    • Information about graph structure
    • Making copies and subgraphs
  • MultiGraph - Undirected graphs with self loops and parallel edges
    • Overview
    • Adding and removing nodes and edges
    • Iterating over nodes and edges
    • Information about graph structure
    • Making copies and subgraphs
  • MultiDiGraph - Directed graphs with self loops and parallel edges
    • Overview
    • Adding and Removing Nodes and Edges
    • Iterating over nodes and edges
    • Information about graph structure
    • Making copies and subgraphs
[ Graph types]

皮皮blog



使用Python与NetworkX获取数据

>>> import networkx as net
>>> import urllib

NetworkX以图(graph)为基本数据结构。图既可以由程序生成,也可以来自在线数据源,还可以从文件与数据库中读取。现在,让我们手动创建一个简单的图(见图3-1):
>>> g=net.Graph()  #创建空图
>>> g.add_edge('a','b') #插入一条连接a,b的边到图中,节点将自动插入
>>> g.add_edge('b','c') #再插入一条连接b,c的边
>>> g.add_edge('c','a') #再插入一条连接c,a的边
>>> net.draw(g)         #输出一个三角形的图
python网络绘图库networkx_第1张图片
 

你也可以将图的节点与边作为Python列表输出:
>>>> g.nodes() #输出图g的节点值
['a','b','c']
>>>> g.edges() #输出图g的边值
[('a', 'c'), ('a', 'b'), ('c', 'b')]

NetworkX中的图数据结构就像Python的 字典(dict) 一样——一切都能循环,并根据键值读取。
 >>> g.node['a']
 {} 
 >>> g.node['a']['size']=1
 >>> g.node['a']
 {'size' : 1}

节点与边能够存储任意类型字典的属性和任意其他丰富类型的数据:
>>> g['a']  #将临近边及权重作为字典返回输出
{'b': {}, 'c': {}}
>>> g['a']['b']  #返回节点A->B的属性
{}
>>> g['a']['b']['weight']=1  #设置边的属性
>>> g['a']['b']
{'weight' : 1} 

多数的计算社会网络指标也返回一个字典,节点ID作为字典键,指标作为字典的值。你可以像操作任何字典一样操作它们。

[使用Python与NetworkX获取数据]

皮皮blog

from:http://blog.csdn.net/pipisorry/article/details/49839251

ref:NetworkX sourse code download

NetworkX documentation

Gallery — NetworkX图形生成源代码

NetworkX Home

复杂网络分析库NetworkX学习笔记


你可能感兴趣的:(NetworkX,python绘图)