Im studying graphs so I'm trying to draw a graph given a dictionary in python using networkx and matplotlib, this is my code:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
graph = {
"A":["B","C"],
"B":["D","E"],
"C":["E","F"],
"D":["B","G"],
"E":["B","C"],
"F":["C","G"],
"G":["D","F"]
}
x=10
for vertex, edges in graph.items():
G.add_node("%s" % vertex)
x+=2
for edge in edges:
G.add_node("%s" % edge)
G.add_edge("%s" % vertex, "%s" % edge, weight = x)
print("'%s' it connects with '%s'" % (vertex,edge))
nx.draw(G,with_labels=True)
plt.show()
I already tried the function draw_networkx_edge_labels but seems like I need a position for that which I dont have since I add the nodes dynamically, so I need a way to draw the edges labels which fit with my current implementation.
