I am trying to adjust the length of edge between two nodes by following code. But apparently it didn't work. Could anyone guide me where I am making mistake: Please note that I already look at this thread (How to specify edge length in Networkx for calculating shortest distance?) but didn't solve my issue
import networkx as nx
import matplotlib.pyplot as plt
G=nx.Graph()
G.add_nodes_from([1,2])
G.add_edge(1,2, length = 10) # I also replaced length with len but no luck
nx.draw(G,with_labels=True)
plt.show() # display
Returns True if the graph has an edge between nodes u and v. This is the same as v in G[u] or key in G[u][v] without KeyError exceptions.
For NetworkX, a graph with more than 100K nodes may be too large. I'll demonstrate that it can handle a network with 187K nodes in this post, but the centrality calculations were prolonged. Luckily, there are some other packages available to help us with even larger graphs.
nbunch. An nbunch is a single node, container of nodes or None (representing all nodes). It can be a list, set, graph, etc.. To filter an nbunch so that only nodes actually in G appear, use G.
How about this:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_nodes_from([1,2])
G.add_edge(1,2, length = 10)
pos = nx.spring_layout(G)
nx.draw(G, pos)
nx.draw_networkx_edge_labels(G, pos)
plt.show()
It will look like this:
You can also play around with draw_networkx_edge_labels
's parameters to print out just exactly what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With