networkx

How to create a networkx Graph using 2D np array as input

人走茶凉 提交于 2021-01-28 22:48:17
问题 My algorithm outputs the set of vertices describing objects in 3D space (x, y, z). In this case, there are two objects: verts = [[0.1 1. 1. ] [1. 1. 0.1] [1. 0.1 1. ] [1. 1. 1.9] [1. 1.9 1. ] [1.9 1. 1. ] [7.1 8. 8. ] [8. 8. 7.1] [8. 7.1 8. ] [8. 8. 8.9] [8. 8.9 8. ] [8.9 8. 8. ]] There are two tetrahedrons, one confined between centered on (1, 1, 1), the other on (8, 8, 8). My goal is to use breadth-first search to identify that the objects are separate, and then classify each. I have not

How to calculate clustering coefficient of each node in the graph in Python using Networkx

有些话、适合烂在心里 提交于 2021-01-28 20:10:20
问题 I want to calculate the clustering coefficient of each node in the graph using python and Networkx functions. I know there might be a built-in function for this purpose but I want to calculate it by myself but my code is not working. Can someone please point out error? I have tried to test and debug the code. No. of neighbors of each node i.e. n_neighbors are calculated seem to be ok but next code is somehow not running or have some error in it which I'm unable to detect. import matplotlib as

Given a list of coordinates add values to those coordinates until shortest path list changes

十年热恋 提交于 2021-01-28 13:30:31
问题 So I got a question and I was hoping you can point me to the right direction, full context problem, I have a 3D numpy array that I use to create graphs using Networkx and with these graphs I find the shortest path. What I need is that given a set of coordinates add "1" in these coordinates until the list of the shortest path changes (This is just an example, the list of coordinates can have more coordinates), my code is the following: import numpy as np import networkx as nx arr = np.array([[

Mapping nodes sizes and adding legends in cytoscape network

旧街凉风 提交于 2021-01-28 09:19:24
问题 I used networkx package in python to construct multiple networks, where each represents a biological experiment. I then exported these networks as gml files to visualize in cytoscape and make comparisons. In each file, I have two attributes for nodes- i.e., count and color. In cytoscape, I assign the node size to its count. However, there is a huge difference between the counts of nodes, for instance some have a count of 100 while others have a count of 50,000. I would like map the sizes of

Image added to one node of a networkx graph is not displayed

独自空忆成欢 提交于 2021-01-28 07:54:23
问题 I tried adding a jpg image to one specific node of the graph. There is no error, but the image is not displayed in the node. The node I am attempting to ad an image is "KCT BS". img=mpimg.imread('kctbs.jpg') G=nx.Graph() G.add_node(('KCT BS'),attr_dict={'image':'img'}) #added the image to the node named #KCTBS G.add_edges_from([("KCT BS","Placements"),("KCT BS","Courses"),("KCT BS","Faculty"),("KCT BS","Students"),("Faculty","Core:21")],length=100) pos = nx.spring_layout(G, scale=10) nx.draw

Assign a color to each path in NetworkX

南楼画角 提交于 2021-01-28 05:16:56
问题 I have cars,cities and routes. Every city is a node. Every route is a path generated by a car. Different cars will have different path, sometimes paths could be intersected (which means differents cars have found the same city in they path), sometimes not. I would rappresent a graph with all the cities and all the different path and plot the graph with plotly. Example: List of cities: CityA -CityB -CityD -CityZ -CityK List of cars: Car1, Car2 Routes: Car1 will have a path through cityA -

keep the scaling while drawing a weighed networkx

陌路散爱 提交于 2021-01-28 04:46:50
问题 when I draw a weighed networkx, it does not really represented the real weight in terms of distance. I was curious if there is any parameters that I am missing or some other problem. so, I started by making a simulated dataset as following from pylab import plot,show from numpy import vstack,array from numpy.random import rand from scipy.cluster.vq import kmeans,vq from scipy.spatial.distance import euclidean import networkx as nx from scipy.spatial.distance import pdist, squareform, cdist #

Highlighting certain nodes/edges in NetworkX - Issues with using zip()

◇◆丶佛笑我妖孽 提交于 2021-01-28 03:59:46
问题 I able to populate network graph using networkx. My problem is when I want to highlight the path (shortest path for example) the graph cannot generate and it will return error below. nx.draw_networkx_edges(Gr,pos,edgelist=path_edges,edge_color='r',width=10) File "/usr/local/lib/python3.6/site-packages/networkx/drawing/nx_pylab.py", line 578, in draw_networkx_edges if not edgelist or len(edgelist) == 0: # no edges! TypeError: object of type 'zip' has no len() I look for solution and this is

Overlap graph on image using coordinates

♀尐吖头ヾ 提交于 2021-01-27 19:24:12
问题 I have two lists of coordinates: first for x-coordinates and second for y-coordinates. I trying to use them as nodes of a graph. import networkx as nx list_of_coordinates_x = list(4.5 , 4, 67, 578, 68) #random numbers list_of_coordinates_y = list(6.7, 3, 12, 45.555, 692) G=nx.MultiGraph() for i in range(len(list_of_coordinates_x)): G.add_node(i, x = list_of_coordinates_x[i], y = list_of_coordinates_y[i]) if i > 0: G.add_edge(i-1,i) nx.draw(G,node_size=10,with_labels=False) But the all graphs

Reproduce same graph in NetworkX

笑着哭i 提交于 2021-01-27 19:13:42
问题 I would like to improve my graph. There are problems as follow: how to create a consistent graph.the graph itself is not consistent everytime i execute / run the code, it will generate different images. The inconsistent graph is shown in the url. how to customize the whole graph / picture size and to make it bigger how to set a permanent position for an object 'a' so that it will consistently appears at the first / top position how to customize length of arrow for each relationship.