networkx

Subtracting values based on a relationship table

六月ゝ 毕业季﹏ 提交于 2020-06-01 07:43:25
问题 I want to develop some code that will calculate the value of the target location (down gradient) by using a relationship table of targets and sources. The general formula is (value = down gradient - up gradient) or, given my relationship table, (value = target - all contributing source locations). Operationally, what I want to do is similar to one of my other posts, only this time I want to use subtraction. So, let's start with: import pandas as pd import networkx as nx import numpy as np df

Python Networkx with_pandas_edgelist: edges not taking proper color, while specifying node positions

蹲街弑〆低调 提交于 2020-06-01 05:10:07
问题 I am pretty new to Python and started learning networkx to plot a graph for a road network. I have to specify, the node positions. The edge color should be dependent on the weights of the edges. I tried using pandas dataframe to generate edges. The edge colors work fine when position is not specified. The code is attached. import pandas as pd import networkx as nx import matplotlib.pyplot as plt # Necessary file-paths l1 = 'file1.xlsx' l2 = "file2.xlsx" n1 = pd.read_excel(l1) n1.head(10) n2 =

How to find the shortest path between two coordinates in a 2-dimensional array?

安稳与你 提交于 2020-05-30 04:18:09
问题 I am trying to find the shortest way to get from one point in a 2D array (one coordinate with x and y values representing its position in the array) to another. I would like to output an array of coordinates which must be travelled through to get from the initial to the final coordinates. One example of an array like this could be arr = [ [15, 7, 3], [1, 2, 6], [7, 4, 67] ] In this case, we can say that we will begin at arr[0][0] and end at arr[2][2] . Thus, the coordinates would be (0, 0)

AttributeError: 'Graph' object has no attribute 'node'

為{幸葍}努か 提交于 2020-05-28 13:45:01
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

AttributeError: 'Graph' object has no attribute 'node'

独自空忆成欢 提交于 2020-05-28 13:43:47
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

AttributeError: 'Graph' object has no attribute 'node'

被刻印的时光 ゝ 提交于 2020-05-28 13:43:07
问题 I have bellow python code to build knn graph but I have an error: AttributeError: 'Graph' object has no attribute 'node'. It seems that the nx.Graph() has no node attribute but I don't know what should I replace with that. import networkx as nx def knn_graph(df, k, verbose=False): points = [p[1:] for p in df.itertuples()] g = nx.Graph() if verbose: print ("Building kNN graph (k = %d)" % (k)) iterpoints = tqdm(enumerate(points), total=len(points)) if verbose else enumerate(points) for i, p in

Creating curved edges with NetworkX in Python3

谁说我不能喝 提交于 2020-05-27 01:51:48
问题 I would like to use networkx (i would also like to take another framework if you know a better one) to create a graps whose nodes are at fixed positions. At the same time the edges of the graph should not overlap. My previous code looks like this: #!/usr/bin/env python3 import networkx as nx import matplotlib.pyplot as plt # Graph data names = ['A', 'B', 'C', 'D', 'E'] positions = [(0, 0), (0, 1), (1, 0), (0.5, 0.5), (1, 1)] edges = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('D', 'A')]

Creating curved edges with NetworkX in Python3

有些话、适合烂在心里 提交于 2020-05-27 01:49:19
问题 I would like to use networkx (i would also like to take another framework if you know a better one) to create a graps whose nodes are at fixed positions. At the same time the edges of the graph should not overlap. My previous code looks like this: #!/usr/bin/env python3 import networkx as nx import matplotlib.pyplot as plt # Graph data names = ['A', 'B', 'C', 'D', 'E'] positions = [(0, 0), (0, 1), (1, 0), (0.5, 0.5), (1, 1)] edges = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('D', 'A')]

Force nodes positions on concentric circles in graphviz graph

梦想的初衷 提交于 2020-05-24 05:34:46
问题 I am using pygraphviz library to plot a python graph created using networkx library. Overall I am quite happy with the 'neato' layout, which produces something like this: Now, my data is structured in a way that I always have a central node, then a set of nodes that are at distance 1 from the center, and then another set of nodes wich are at distance 2 from the center. By "distance" I mean number of links before reaching the central node. Because of this, I would like to force the position of

networkx search for a node by attributes

风流意气都作罢 提交于 2020-05-17 07:29:04
问题 I look for the more elegent way to search for a node in a DiGraph from o ne of this attributes:: g = nx.DiGraph() g.add_nodes_from([(1, dict(d=0, a=7)), (2, dict(d=0, a=6))]) g.add_nodes_from([(11, dict(d=1, a=4)), (12, dict(d=1, a=9))]) g.add_nodes_from([(21, dict(d=1, a=4)), (121, dict(d=2, a=7))]) g.add_edges_from([(1, 11), (1, 12), (2, 21), (12, 121)]) g.nodes.data() # NodeDataView({1: {'d': 0, 'a': 7}, 2: {'d': 0, 'a': 6}, # 11: {'d': 1, 'a': 4}, 12: {'d': 1, 'a': 9}, # 21: {'d': 1, 'a':