(Python) ValueError: Program dot not found in path
PyGraphviz doesn’t work without Graphviz. Install that too.
PyGraphviz doesn’t work without Graphviz. Install that too.
There is a linear-time algorithm mentioned at http://en.wikipedia.org/wiki/Longest_path_problem Here is a (very lightly tested) implementation EDIT, this is clearly wrong, see below. +1 for future testing more than lightly before posting import networkx as nx def longest_path(G): dist = {} # stores [node, distance] pair for node in nx.topological_sort(G): pairs = [[dist[v][0]+1,v] for v in … Read more
Simplest version (another version is below which I think is faster): def findPaths(G,u,n): if n==0: return [[u]] paths = [[u]+path for neighbor in G.neighbors(u) for path in findPaths(G,neighbor,n-1) if u not in path] return paths This takes a network G and a node u and a length n. It recursively finds all paths of length … Read more
The command draw_networkx_edge_labels needs the argument edge_labels rather than labels. So you need to change nx.draw_networkx_edge_labels(G, pos, labels = edge_labels) to nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels)
I made a small csv called mycsv.csv that has the following: ,a,b,c,d a,0,1,0,1 b,1,0,1,0 c,0,1,0,1 d,1,0,1,0 You don’t have a ‘,’ as the first character on the first row, but instead you have a space, so if this is an error on my part let me know. The general idea will be the same. Read … Read more
There is a small bug in the draw_graphviz function in networkx-1.11 triggered by the change that the graphviz drawing tools are no longer imported into the top level namespace of networkx. The following is a workaround In [1]: import networkx as nx In [2]: G = nx.complete_graph(5) In [3]: from networkx.drawing.nx_agraph import graphviz_layout In [4]: … Read more
I believe your problem is similar to that in AttributeError: ‘DiGraph’ object has no attribute ‘_node’ The issue there is that the graph being investigated was created in networkx 1.x and then pickled. The graph then has the attributes that a networkx 1.x object has. I believe this happened for you as well. You’ve now … Read more
Did you want something like this use nx.draw_networkx_nodes using nodelist parameter: # Author: Aric Hagberg ([email protected]) 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) … Read more
This is hitting a known (but unresolved) bug in the OSX backend (#3470). Switching to one of the Agg based backends should ‘resolve’ the problem by avoiding it. UPDATE Part of the problem has been identified and merged https://github.com/matplotlib/matplotlib/pull/3564. This fix should be in mpl v1.4.1 and higher.
igraph, another graph module for Python can calculate all the shortest paths between a given pair of nodes. Calculating all the paths does not make sense as you have infinitely many such paths. An example for calculating all the shortest paths from vertex 0: >>> from igraph import Graph >>> g = Graph.Lattice([10, 10], circular=False) … Read more