networkx

Generate all paths in an efficient way using networkx in python

本秂侑毒 提交于 2020-03-25 19:46:28
问题 I am trying to generate all paths with at most 6 nodes from every origin to every destination in a fairly large network (20,000+ arcs). I am using networkx and python 2.7. For small networks, it works well but I need to run this for the whole network. I was wondering if there is a more efficient way to do this in python. My code contains a recursive function (see below). I am thinking about keeping some of the paths in memory so that I don't create them again for other paths but I am not sure

Extract constrained polygon using OSMnx

自闭症网瘾萝莉.ら 提交于 2020-03-22 09:48:26
问题 I'm playing around with OSMnx package in order to solve the following task: - there is a point X on the map defined by latitude and longitude - we need to detect a polygon that contains that point X and is constrained by the neighboring roads - so basically the point X is inside the polygon and the neighboring roads will be borders of that polygon. So far I've managed only to plot the visualization of the graph on the map and find the closest edge/node to point X. In the attached image I've

python网络画图——networkX

流过昼夜 提交于 2020-03-19 06:14:42
networkX tutorial 绘制基本网络图 用matplotlib绘制网络图 基本流程: 1. 导入networkx,matplotlib包 2. 建立网络 3. 绘制网络 nx.draw() 4. 建立布局 pos = nx.spring_layout美化作用 最基本画图程序 1 import networkx as nx #导入networkx包 2 import matplotlib.pyplot as plt 3 G = nx.random_graphs.barabasi_albert_graph(100,1) #生成一个BA无标度网络G 4 nx.draw(G) #绘制网络G 5 plt.savefig("ba.png") #输出方式1: 将图像存为一个png格式的图片文件 6 plt.show() #输出方式2: 在窗口中显示这幅图像 networkx 提供画图的函数有: draw (G,[pos,ax,hold]) draw_networkx (G,[pos,with_labels]) draw_networkx_nodes (G,pos,[nodelist]) 绘制网络G的节点图 draw_networkx_edges (G,pos[edgelist]) 绘制网络G的边图 draw_networkx_edge_labels (G, pos[, ...])

Python3画图系列——NetworkX初探

…衆ロ難τιáo~ 提交于 2020-03-19 06:11:35
NetworkX 概述 NetworkX 主要用于 创造、操作复杂网络 ,以及学习复杂网络的结构、动力学及其功能。用于分析网络结构,建立网络模型,设计新的网络算法,绘制网络等等。安装networkx看以参见 官网 。 NetworkX学习 关于networkx的学习可以参考如下网站: python复杂网络库networkx:基础 网络分析之networkx python networkx学习 案例学习 学习案例前,请先导入下面的库 import networkx as nx import matplotlib.pyplot as plt 案例1 G = nx.Graph() G.add_node(1) G.add_edge(2, 3) # G.add_edge(3, 2) print("输出全部节点:{}".format(G.nodes())) print("输出全部边:{}".format(G.edges())) print("输出全部边的数量:{}".format(G.number_of_edges())) nx.draw(G) plt.show() 输出全部节点:[1, 2, 3] 输出全部边:[(2, 3)] 输出全部边的数量:1 案例2 G = nx.DiGraph() G.add_node(1) G.add_node(2) G.add_nodes_from([3, 4,

Multi-layer graph in networkx

廉价感情. 提交于 2020-03-03 14:03:10
问题 I want to create a multi-layered graph (like in the attached image), by connecting the two graphs written with the following code, using networkx #Graph1 g1 = nx.read_edgelist('sample.txt', nodetype=str) pos = nx.shell_layout(g) plt.figure(figsize=(10, 10)) nx.draw_networkx_edges(g, pos, edge_color='khaki', alpha=1) nx.draw_networkx_nodes(g,pos,node_color='r',alpha=0.5,node_size=1000) nx.draw_networkx_labels(g, pos, font_size=10,font_family='IPAexGothic') plt.axis('off') #Graph2 g2 = nx.read

Multi-layer graph in networkx

微笑、不失礼 提交于 2020-03-03 14:02:26
问题 I want to create a multi-layered graph (like in the attached image), by connecting the two graphs written with the following code, using networkx #Graph1 g1 = nx.read_edgelist('sample.txt', nodetype=str) pos = nx.shell_layout(g) plt.figure(figsize=(10, 10)) nx.draw_networkx_edges(g, pos, edge_color='khaki', alpha=1) nx.draw_networkx_nodes(g,pos,node_color='r',alpha=0.5,node_size=1000) nx.draw_networkx_labels(g, pos, font_size=10,font_family='IPAexGothic') plt.axis('off') #Graph2 g2 = nx.read

使用networkx-python绘制点边图

我只是一个虾纸丫 提交于 2020-03-02 08:23:59
环境:win7(AMD32bit) + python2.6 + network1.8.1 依赖: numpy https://pypi.python.org/packages/2.6/n/numpy/numpy-1.6.1.win32-py2.6.exe#md5=67e0c10cf55b713bd27cbba94dee9673 pyparsing http://ncu.dl.sourceforge.net/project/pyparsing/pyparsing/pyparsing-2.0.1/pyparsing-2.0.1.win32-py2.6.exe datautil https://pypi.python.org/packages/source/p/python-dateutil/python-dateutil-2.2.tar.gz#md5=c1f654d0ff7e33999380a8ba9783fd5c matplotlib http://ncu.dl.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.1/matplotlib-1.3.1.win32-py2.6.exe networkx https://pypi.python.org/packages/source/n/networkx

networkx(三)

北战南征 提交于 2020-02-07 02:46:10
Graph—Undirected graphs with self loops 具有自循环的无向图 import networkx as nx G = nx . Graph ( ) #创建一个没有节点也没有边的空的无向图 G . add_node ( 1 ) #一次添加一个节点来生成无向图 你也可以从list dict set甚至是文件的一行以及把另一个图作为节点作为节点 G . add_nodes_from ( [ 2 , 3 ] ) G . add_nodes_from ( range ( 100 , 110 ) ) G . nodes ( ) NodeView((1, 2, 3, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109)) H = nx . path_graph ( 10 ) H <networkx.classes.graph.Graph at 0x204f6b3f470> G . add_nodes_from ( H ) G . nodes ( ) NodeView((1, 2, 3, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 0, 4, 5, 6, 7, 8, 9)) 除了字符串和整数外,任何可散列的Python对象(“None”除外)都可以表示一个节点

How to split tuple with parentheses in Python?

大城市里の小女人 提交于 2020-02-06 06:33:07
问题 I have built-in tuple which looks like (u,v) . They are generated by Networkx and they show links in a graph. I make a list out of the called link_list . I have to split the tuple such that the outcome would be: u , v I tried divmod but it doesn't give the right answer. for link in link_list: u,v = divmod(*link) print u,v 回答1: Simple: for link in link_list: u, v = link print u, v It's called sequence unpacking. 回答2: you can get the tuple into individual variables in the for statement as

How to split tuple with parentheses in Python?

戏子无情 提交于 2020-02-06 06:31:01
问题 I have built-in tuple which looks like (u,v) . They are generated by Networkx and they show links in a graph. I make a list out of the called link_list . I have to split the tuple such that the outcome would be: u , v I tried divmod but it doesn't give the right answer. for link in link_list: u,v = divmod(*link) print u,v 回答1: Simple: for link in link_list: u, v = link print u, v It's called sequence unpacking. 回答2: you can get the tuple into individual variables in the for statement as