networkx

Creating cliques from connected components using networkx

余生长醉 提交于 2020-01-06 06:51:07
问题 I have created a graph using networkx in Python . import networkx as nx G = createGraph ('abc.csv') #My function that returns graph from file. connected_components = nx.connected_components(G) print (connected_components) <generator object connected_components at 0x00000000221EF1A8> nbr_cc = nx.number_connected_components(G) print (nbr_cc) 57215 I want to convert every connected component into a clique and then write a csv file in following manner: node1_id node2_id connected_component_id 1 2

OSMnx Add Title to Graph Plot

我们两清 提交于 2020-01-06 05:59:15
问题 I'm using the wonderful OSMnx library created by Geoff Boeing. I am plotting a street network based on one of his tutorials. Everything works perfectly. However, I would like to plot more than 40 graphs, using different centralities. Therefore, I would like to add a title with each district and centrality name to each plot. Currently, it looks like this. Plotted OSMnx Street Network This is what my code looks like. def display_most_important_node(G_centralities_sorted_dict, G_dictionary,

Why the result is incorrect to find 3-cliques using networkx in Python?

心已入冬 提交于 2020-01-06 03:40:07
问题 I am trying to find all 3-cliques using networkx's find_cliques method. However, there should be far more than 2 as the result shows. Please help me to figure out why. import networkx as nx G = nx.Graph() edges_fig_4 = [('a','b'),('a','c'),('a','d'),('a','e'), ('b','c'),('b','d'),('b','e'), ('c','d'),('c','e'), ('d','e'),('e','d'), ('f','b'),('f','c'),('f','g'), ('g','f'),('g','c'),('g','d'),('g','e')] G.add_edges_from(edges_fig_4) cliques = nx.find_cliques(G) cliques3 = [clq for clq in

len throws with 'dict_keyiterator' has no len() when calculating outgoing and incoming edges in networkx

感情迁移 提交于 2020-01-06 02:38:25
问题 I am implementing a graph manipulation script and I was puzzled with the following error: Traceback (most recent call last): File ".....py", line 12, in <module> print(len(graph.predecessors(i)), len(graph.successors(i))) >>TypeError: object of type 'dict_keyiterator' has no len()<< This is the code: import networkx as nx graph = nx.DiGraph() for i in range(10): graph.add_node(i) for i in range(9): graph.add_edge(i, i+1) for i in range(10): print(len(graph.predecessors(i)), len(graph

Networkx parse gml writing unusable gml files

江枫思渺然 提交于 2020-01-05 07:48:12
问题 I've been trying to parse in some additional attributes to a networkx gml for use later on, and I've run into an issue. When given a gml file from Cytoscape, networkx outputs a gml file that it itself can't read. I.e. Cytoscape -> Into networkx -> Output -> Into networkx -> Error: pyparsing.ParseException: Expected "]" (at char 1116756), (line:71732, col:3) Now that error requests an additional ] after the nodes (AKA making the graph ignore the edges), if you do this, the graph works. However

Networkx parse gml writing unusable gml files

荒凉一梦 提交于 2020-01-05 07:47:48
问题 I've been trying to parse in some additional attributes to a networkx gml for use later on, and I've run into an issue. When given a gml file from Cytoscape, networkx outputs a gml file that it itself can't read. I.e. Cytoscape -> Into networkx -> Output -> Into networkx -> Error: pyparsing.ParseException: Expected "]" (at char 1116756), (line:71732, col:3) Now that error requests an additional ] after the nodes (AKA making the graph ignore the edges), if you do this, the graph works. However

Follow-up: add edge connecting nodes of two separate graphs in Python using NetworkX

倖福魔咒の 提交于 2020-01-05 05:58:09
问题 I am fairly proficient in C++, but I am learning python, NetworkX, and about pythonic code all at the same time. After reading various websites and the reference my question is the same as this question. The difference is the approach I am taking to implement my task. Please note this question is about adding an edge, not drawing. I have a graph (SAR), whose nodes are also graphs (Boat, and Adrift), import networkx as nx import math # User Inputs Num_Adrift = 4 # Cluster Definition Boat = nx

Export graph to graphml with node positions using NetworkX

匆匆过客 提交于 2020-01-05 04:33:15
问题 I'm using NetworkX 1.9.1. I have a graph that I need to organize with positions and I then export to graphml format. I've tried code in this question. It does not work, here is my example import networkx as nx import matplotlib.pyplot as plt G = nx.read_graphml("colored.graphml") pos=nx.spring_layout(G) # an example of quick positioning nx.set_node_attributes(G, 'pos', pos) nx.write_graphml(G, "g.graphml") nx.draw_networkx(G, pos) plt.savefig("g.pdf") Here are the errors I get, the problem is

OSMnx Visualize the graph of edge centrality on Folium

跟風遠走 提交于 2020-01-04 09:47:07
问题 I'm trying to plot the graph of edge centrality on the folium using the following code graph_map = ox.plot_graph_folium(G, popup_attribute='name', tiles='stamenterrain', edge_color=ec, edge_width=2) where ec is list of edge colors but it is not showing up. Does edge_color accept a list of colors ? Any ideas? I really appreciate if you can help me. https://github.com/gboeing/osmnx-examples/blob/master/notebooks/08-example-line-graph.ipynb 回答1: I tried adding a new column of edge color to gdf

OSMnx Visualize the graph of edge centrality on Folium

[亡魂溺海] 提交于 2020-01-04 09:43:49
问题 I'm trying to plot the graph of edge centrality on the folium using the following code graph_map = ox.plot_graph_folium(G, popup_attribute='name', tiles='stamenterrain', edge_color=ec, edge_width=2) where ec is list of edge colors but it is not showing up. Does edge_color accept a list of colors ? Any ideas? I really appreciate if you can help me. https://github.com/gboeing/osmnx-examples/blob/master/notebooks/08-example-line-graph.ipynb 回答1: I tried adding a new column of edge color to gdf