networkx

Networkx: Use common function for edge weight calculation

放肆的年华 提交于 2020-01-13 21:41:45
问题 Suppose I have a function euc_2d(graph, n1, n2) that calculates the euclidean distance between two nodes of the same graph. Each nodes has a given pos=(x,y) which is assigned on graph creation. NetworkX provides a function to get the total weight of all edges of a graph namely graph.size(weight='weight') . The problem with this method is that it assumes that whenever I add an edge I should explicitly assign the appropriate edge weight like graph.add_edge(u,v,weight=?) using a lambda function

NetworkX-style spring model layout for directed graphs in Graphviz / PyGraphviz

落爺英雄遲暮 提交于 2020-01-13 19:12:51
问题 NetworkX is mostly for graph analysis, PyGraphviz mostly for drawing, and they're designed to work together. However, there's at least one respect in which NetworkX's graph drawing (via MatPlotLib) is superior to PyGraphviz's graph drawing (via Graphviz), namely that NetworkX has a spring layout algorithm (accessible via the spring_layout function) specifically for directed graphs while PyGraphviz has several spring layout algorithms (accessible via the neato program, and others) that lay out

Faster way to calculate the number of shortest paths a vertex belongs to using Networkx

风流意气都作罢 提交于 2020-01-13 18:59:00
问题 I am considering that the Stress of a vertex i is the number of shortest paths between all pairs of vertices that i belongs to. I am trying to calculate it using Networkx, I've made in three ways so far. The readable , dirty , and dirtiest but none of them is fast. Actually, I would like it to be faster than the betweenness (source) present on Networkx. Is there a better way to calculate that? Thanks in advance for any suggestion, answer or comment. Following see what I did so far: Ps.: Here

Faster way to calculate the number of shortest paths a vertex belongs to using Networkx

偶尔善良 提交于 2020-01-13 18:58:06
问题 I am considering that the Stress of a vertex i is the number of shortest paths between all pairs of vertices that i belongs to. I am trying to calculate it using Networkx, I've made in three ways so far. The readable , dirty , and dirtiest but none of them is fast. Actually, I would like it to be faster than the betweenness (source) present on Networkx. Is there a better way to calculate that? Thanks in advance for any suggestion, answer or comment. Following see what I did so far: Ps.: Here

How can one modify the outline color of a node In networkx?

时光毁灭记忆、已成空白 提交于 2020-01-13 07:47:47
问题 I am relatively new to networkx and plotting using matplotlib.pyplot and would like to know how to modify the color (or other attributes such as weight) of a node's outline. By "outline" I don't mean an arc or edge between two nodes; I mean the thin black line around the circle that is by default used to represent a node when plotting a network. So for example, when I make a graph that has just a single node and display it: from networkx import * import matplotlib.pyplot as plt plt.ion() G =

How to plot the outline of the outer edges on a Matplotlib line in Python?

三世轮回 提交于 2020-01-12 07:22:46
问题 I am trying to plot an outline ( linestyle=":" ) on the networkx edges. I can't seem to figure out how to do this to the matplotlib patch objects? Does anyone now how to manipulate these patch object to plot outlines to these "edges"? If this is not possible, does anyone know how to get the line data to use ax.plot(x,y,linestyle=":") separately to do this? import networkx as nx import numpy as np from collections import * # Graph data G = {'y1': OrderedDict([('y2', OrderedDict([('weight', 0

How to change attributes of a networkx / matplotlib graph drawing?

懵懂的女人 提交于 2020-01-12 05:32:07
问题 NetworkX includes functions for drawing a graph using matplotlib. This is an example using the great IPython Notebook (started with ipython3 notebook --pylab inline ): Nice, for a start. But how can I influence attributes of the drawing, like coloring, line width and labelling? I have not worked with matplotlib before. 回答1: IPython is a great tool for finding out what functions (and objects) can do. If you type [1]: import networkx as nx [2]: nx.draw? you see Definition: nx.draw(G, pos=None,

python check string contains all characters

99封情书 提交于 2020-01-11 14:29:29
问题 I'm reading in a long list of words, and I made a node for every word in the list. Each node has an attribute 'word' for their position in the list. I am trying to connect a node to the next node if the next node is the previous node, with an addition of just one letter I also alphabetically ordered each word per character, so that CAT -> ACT I want to draw an edge from each unique starting word, to all of the possible chains, so I can see all the possible chains in the list. For example A ->

python check string contains all characters

不羁岁月 提交于 2020-01-11 14:29:26
问题 I'm reading in a long list of words, and I made a node for every word in the list. Each node has an attribute 'word' for their position in the list. I am trying to connect a node to the next node if the next node is the previous node, with an addition of just one letter I also alphabetically ordered each word per character, so that CAT -> ACT I want to draw an edge from each unique starting word, to all of the possible chains, so I can see all the possible chains in the list. For example A ->

Method to save networkx graph to json graph?

左心房为你撑大大i 提交于 2020-01-10 08:44:26
问题 Seems like there should be a method in networkx to export the json graph format, but I don't see it. I imagine this should be easy to do with nx.to_dict_of_dicts(), but would require a bit of manipulation. Anyone know of a simple and elegant solution? 回答1: This documentation contains a full description A simple example is this: import networkx as nx from networkx.readwrite import json_graph DG = nx.DiGraph() DG.add_edge('a', 'b') print json_graph.dumps(DG) You can also take a look at the