networkx

Curved edges in NetworkX

拟墨画扇 提交于 2020-12-12 04:38:13
问题 I currently have the following code for my networkx graph: import matplotlib.pyplot as plt import networkx as nx G = nx.Graph() G.add_edge("a", "b", weight=0.6) G.add_edge("a", "c", weight=0.2) G.add_edge("c", "d", weight=0.1) G.add_edge("c", "e", weight=0.7) G.add_edge("c", "f", weight=0.9) G.add_edge("a", "d", weight=0.3) elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] > 0.5] esmall = [(u, v) for (u, v, d) in G.edges(data=True) if d["weight"] <= 0.5] pos = nx.circular

Reverse one edge in networkx graph

混江龙づ霸主 提交于 2020-12-08 07:33:36
问题 I found DiGraph.reverse() to reverse the direction of all edges in the directed graph, but is there a way to change the direction of a specific edge only? 回答1: It can certainly be done manually, but there's nothing in the API for it. $ cat edges.py; echo; python edges.py import networkx as nx G=nx.DiGraph() G.add_edge(1,2,{'weight':.5}) G.add_edge(3,4,{'weight':1.0}) attrs = G[1][2] G.remove_edge(1,2) G.add_edge(2,1,attrs) print G.edges(data=True) [(2, 1, {'weight': 0.5}), (3, 4, {'weight': 1

Building terms relations within a network

不想你离开。 提交于 2020-12-08 01:50:31
问题 I am trying to represent relationships between numbers in column A and their corresponding values in B. A B Home [Kitchen, Home, Towel] Donald [US, 02 , Donald, Trump] Trump [Trump,Family, Cat, Dog] Dog [Dog,Cat,Paws] Numbers in column A and numbers in B are nodes in a graph. I would like to connect elements in B to A or to each other. For example: Home in A is linked with itself; if I look within B column (the value appears only in the first row), Home in B is connected to Kitchen and Towel

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'

一曲冷凌霜 提交于 2020-12-06 04:40:22
问题 B = nx.Graph() B.add_nodes_from(data['movie'].unique(), bipartite=0, label='movie') B.add_nodes_from(data['actor'].unique(), bipartite=1, label='actor') B.add_edges_from(edges, label='acted') A = list(nx.connected_component_subgraphs(B))[0] I am getting the below given error when am trying to use nx.connected_component_subgraphs(G). Please help with this issue. In the dataset there are two coumns(movie and actor), and it's in the form bipartite graph. I want to get connected components for

AttributeError: module 'networkx' has no attribute 'connected_component_subgraphs'

时光毁灭记忆、已成空白 提交于 2020-12-06 04:37:01
问题 B = nx.Graph() B.add_nodes_from(data['movie'].unique(), bipartite=0, label='movie') B.add_nodes_from(data['actor'].unique(), bipartite=1, label='actor') B.add_edges_from(edges, label='acted') A = list(nx.connected_component_subgraphs(B))[0] I am getting the below given error when am trying to use nx.connected_component_subgraphs(G). Please help with this issue. In the dataset there are two coumns(movie and actor), and it's in the form bipartite graph. I want to get connected components for

How to 'zoom' to a specific area in an osmnx plot

 ̄綄美尐妖づ 提交于 2020-12-06 02:59:29
问题 I have a osmnx plot that has two routes, but the map is quite vast therefore I cannot see the routes properly. Is there a fast way to limit my plot, to sort of 'zoom in', using for example bbox ? I know I could search for districts instead of a whole city, I was just curious to know if there was a fastest way to 'zoom' in the plot. Here is the code: import osmnx as ox import igraph as ig import matplotlib.pyplot as plt import pandas as pd import networkx as nx import numpy as np import

Networkx: Get the distance between nodes

故事扮演 提交于 2020-11-30 06:46:45
问题 I'm a beginner at using NetworkX and I'm trying to find a way to detect which nodes have distance x from each other. I've started by using this algorithm to get all pairs path=nx.all_pairs_dijkstra_path(G) But I'm still unsure on how to detect the distance between nodes using a for loop. I'd appreciate any help. Thank you 回答1: NetworkX has methods for automatically calculating the shortest paths (or just the path lengths) for weighted and unweighted graphs. Make sure that you use the correct

Select network nodes with a given attribute value

混江龙づ霸主 提交于 2020-11-30 06:22:20
问题 I'd like to select and perform operations on nodes within a graph with particular attributes. How would you select nodes with a given attribute value? For example: P=nx.Graph() P.add_node('node1',at=5) P.add_node('node2',at=5) P.add_node('node3',at=6) Is there a way to select only the nodes with at == 5?. I'm imagining something like (this doesn't work): for p in P.nodes(): P.node[p]['at'==5] 回答1: Python <= 2.7: According to the documentation try: nodesAt5 = filter(lambda (n, d): d['at'] == 5

Select network nodes with a given attribute value

痞子三分冷 提交于 2020-11-30 06:19:07
问题 I'd like to select and perform operations on nodes within a graph with particular attributes. How would you select nodes with a given attribute value? For example: P=nx.Graph() P.add_node('node1',at=5) P.add_node('node2',at=5) P.add_node('node3',at=6) Is there a way to select only the nodes with at == 5?. I'm imagining something like (this doesn't work): for p in P.nodes(): P.node[p]['at'==5] 回答1: Python <= 2.7: According to the documentation try: nodesAt5 = filter(lambda (n, d): d['at'] == 5

Read/Write NetworkX Graph Object

寵の児 提交于 2020-11-30 04:31:09
问题 I am trying to deal with a super-massive NetworkX Graph object with hundreds of millions of nodes. I'd like to be able to write it to file as to not consume all my computer memory. However, I need to constantly be searching across existing nodes, updating edges, etc. Is there a good solution for this? I'm not sure how it would work with any of the file formats provided on http://networkx.lanl.gov/reference/readwrite.html The only solution i can think of is to store each node as a separate