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

其它复杂网络绘图库

[SNAP for python]

[ArcGIS,Python,网络数据集中查询两点最短路径]

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
  • DiGraph - Directed graphs with self loops
  • MultiGraph - Undirected graphs with self loops and parallel edges
  • 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

子图subgraphs

Graph.subgraph(nbunch)

参数nbunch指定子图的节点

返回原图上的子图

[subgraphs]

二分网络

建立二分网络
import networkx
from network.algorithm import bipartite
g.add_edges_from([("nodename1","nodename2"),("nodename3","nodename1")])

判断是否是二分网络
print  bi_partite.is_bipartite(g)

得到两端网络
NSet = nx.bipartite.sets(g)
Net1 = nx.project(g,NSet[0])
Net2 = nx.project(g,Nset[1])

[Graph types]

皮皮blog

networkx的使用

import networkx as nx

使用Python与NetworkX获取数据:基本使用

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

NetworkX以图(graph)为基本数据结构。图既可以由程序生成,也可以来自在线数据源,还可以从文件与数据库中读取。
>>> 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列表输出:
>>>> 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获取数据]

图Graph

degree(G[, nbunch, weight]) Return degree of single node or of nbunch of nodes.
degree_histogram(G) Return a list of the frequency of each degree value.
density(G) Return the density of a graph.
info(G[, n]) Print short summary of information for the graph G or the node n.
create_empty_copy(G[, with_nodes]) Return a copy of the graph G with all of the edges removed.
is_directed(G) Return True if graph is directed.

节点Nodes

nodes(G) Return a copy of the graph nodes in a list.
number_of_nodes(G) Return the number of nodes in the graph.
nodes_iter(G) Return an iterator over the graph nodes.
all_neighbors(graph, node) Returns all of the neighbors of a node in the graph.
non_neighbors(graph, node) Returns the non-neighbors of the node in the graph.
common_neighbors(G, u, v) Return the common neighbors of two nodes in a graph.

边edges

边相关方法

edges(G[, nbunch]) Return list of edges incident to nodes in nbunch.
number_of_edges(G) Return the number of edges in the graph.
edges_iter(G[, nbunch]) Return iterator over edges incident to nodes in nbunch.
non_edges(graph) Returns the non-existent edges in the graph.

有序边

target_subgraph.edges()返回的边是无序的。

修改成有序:sortEdges = lambda l: [(n1, n2) if n1 <= n2 else (n2, n1) for n1, n2 in l]

G.number_of_edges()

方法其实是图类的方法G.number_of_edges()

number_of_edges(self, u=None, v=None):
"""Return the number of edges between two nodes

获取属性Attributes

set_node_attributes(G, name, values) Set node attributes from dictionary of nodes and values
get_node_attributes(G, name) Get node attributes from graph
set_edge_attributes(G, name, values) Set edge attributes from dictionary of edge tuples and values.
get_edge_attributes(G, name) Get edge attributes from graph

获取边属性get_edge_attributes(G, name)

返回的是一个key为边的dict

edges_weight_index = nx.get_edge_attributes(target_subgraph, 'weight')

edges_weight_index[(u, v)]

[functions#edges]

添加边

g=net.Graph()  #创建空图

g.add_edge('a','b') #插入一条连接a,b的边到图中,节点将自动插入

批量添加有权边

g.add_weighted_edges_from([(1,2,0.125),(1,3,0.75),(2,4,1.2),(3,4,0.375)])

绘制有权图[Weighted Graph]

[Edges]

from:python复杂网络库networkx:基础_皮皮blog-CSDN博客

ref: [Functions]*

[Networkx Reference]*[NetworkX documentation]*[doc NetworkX Examples]*[NetworkX Home]

[NetworkX sourse code download]

[Gallery — NetworkX图形生成源代码]

[sciencenet 复杂网络分析库NetworkX学习笔记]*

[networkx笔记系列]

python复杂网络库networkx:基础相关推荐

  1. Python操作lxml库(基础篇)

    ​ 活动地址:CSDN21天学习挑战赛 学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩:迟一天就多一天平庸的困扰. 学习日记 目录 目录 学习日记 一.lxml库概述 1.lxml库介绍 2.l ...

  2. python的turtle库的基础函数及其使用

    python的turtle库的基础函数及其使用 博主新建的Python学习QQ群分享一些实用的学习工具和疑问解答以及源码分享欢迎加入:431615454. 基础知识点 本篇文章主要介绍一部分自己喜欢用 ...

  3. 一文读懂Python复杂网络分析库networkx | CSDN博文精选

    作者 | yyl424525 来源 | CSDN博客 文章目录 1. 简介 安装 支持四种图 绘制网络图基本流程 2. Graph-无向图 节点 边 属性 有向图和无向图互转 3. DiGraph-有 ...

  4. Python复杂网络分析库networkx 看这一篇就够了

    文章目录 1 基础知识 1.1 简介 1.2 Graph 添加节点 访问节点 删除节点 添加边 访问边 遍历边 生成小世界网络 生成规则网络 另一种规则图 ER随即图 BA无标度网络 喜欢的话请关注我 ...

  5. 深入Go语言网络库的基础实现

    https://studygolang.com/articles/1879 Go语言的出现,让我见到了一门语言把网络编程这件事情给做"正确"了,当然,除了Go语言以外,还有很多语言 ...

  6. python复杂网络全局效率计算_python复杂网络库networkx:算法

    Networks算法Algorithms 最短路径Shortest Paths 简单路径Simple Paths all_simple_paths(G, source, target[, cutoff ...

  7. python socket server库_python基础之socket与socketserver

    ---引入 Socket的英文原义是"孔"或"插座",在Unix的进程通信机制中又称为'套接字'.套接字实际上并不复杂,它是由一个ip地址以及一个端口号组成.S ...

  8. networkx edge 属性_一文读懂Python复杂网络分析库networkx | CSDN博文精选

    作者 | yyl424525 来源 | CSDN博客 文章目录 1. 简介 安装 支持四种图 绘制网络图基本流程 2. Graph-无向图 节点 边 属性 有向图和无向图互转 3. DiGraph-有 ...

  9. python面试题库——1Python基础篇

    第一部分 Python基础篇(80题) 为什么学习Python? 语言本身简洁,优美,功能超级强大,跨平台,从桌面应用,web开发,自动化测试运维,爬虫,人工智能,大数据处理都能做 Python和Ja ...

  10. python手机题库app_Python基础_学习通app_期末答案

    Python基础_学习通app_期末答案 更多相关问题 [单选] 单纯性肥胖患儿一般不会发生下列哪种情况() [单选] 3岁男孩,近半年食欲差,喜吃墙皮,易患上感.查体:身高90cm,除地图舌外未发现 ...

最新文章

  1. 10+小故事揭秘高频「操作系统面试题」
  2. ETC2 区别于ETC的重要点
  3. 用numpy把一个矩阵的一行或一列删除,再把剩下的拼在一起
  4. 小程序 封装table组件
  5. 阿里P8架构师谈:Web前端、应用服务器、数据库SQL等性能优化总结
  6. TY_GASPX SQL
  7. window10运行不了1stopt_函数模型分析画图软件-1stopt非线性拟合工具Win10专业版1.7免费版 - 维维软件园...
  8. python代码翻译器-Python实现翻译软件
  9. android图片浮动层,android浮层图片拖动并且可点击效果
  10. ETS 题库 c java_最新ETS阅读真题56篇完整版(TPO+ETS在线试题+官方模拟题+OG)
  11. excel自动求和_瞬间搞定一月数据汇总!这个Excel求和公式太牛了
  12. 第一次尝试公司项目上线
  13. 添加网络计算机后打印乱码,Windows7系统打印机无法打印出现乱码的解决方法
  14. php ping 域名,怎么利用PHP去ping一个地址_PHP
  15. Intrinsics函数Tips与踩坑
  16. 客2消,客1消,客0消...脉脉劝退客户端多次的你们究竟是何用意?
  17. 怎么扫描图片存为电子版?只需要几步小操作
  18. 沈航-数理统计-17-18B-有答案
  19. 微信高级群发之预览接口
  20. CityMaker学习教程11 创建和移动标签

热门文章

  1. Android项目实战之(1)-- 开发一个快速冲浪的程序
  2. Docker Swarm学习教程
  3. poj 1905 Expanding Rods (数学 计算方法 二分)
  4. 如何保证数据库结构的合理性(三、建立可靠的关系)
  5. Eclipse 插件开发 资料贡献
  6. Visual Studio 2017常见用法及相关配置
  7. Windows 2016 安装单机版本Oracle ASM 的简单说明
  8. 阿里云服务器windows系统上Nodejs监听80端口报错!
  9. The content of the adapter has changed but ListView did not receive a notification
  10. 无错版Vsftpd Mysql Pam设置虚拟用户要领