I'm trying to create a directed graph with weighted edges from the networkx library. The graph as shown in the picture is what im trying to achieve
This is the code I've got so far
import networkx as nx
import matplotlib.pyplot as plt
import pandas as panda
df = panda.DataFrame({'from':['R','R','D04','D04','D06','D06'], 'to':['D04','D06','R','D06','R','D04']})
G=nx.from_pandas_edgelist(df, 'from', 'to', create_using=nx.DiGraph())
G['R']['D04']['weight'] = 243.0
G['R']['D06']['weight'] = 150.0
G['D06']['D04']['weight'] = 211.0
pos = nx.spring_layout(G)
labels = nx.get_edge_attributes(G,'weight')
nx.draw_networkx_edge_labels(G,pos, edge_labels=labels)
# Make the graph
nx.draw(G, with_labels=True, node_size=1500, alpha=0.3, font_weight="bold", arrows=True)
plt.axis('on')
plt.show()
Pictures of what im getting:
I'm having a hard time figuring out how to enable the X/Y-axis. I don't know the placement of the different nodes, only that the Router node ('R') should be placed in (0,0). Furthermore my edge weights seem to be placed at random. Sometimes they are placed nicely, other times they go flying off. And lastly the directed edges seem to be straight, and not bent as wished. I've read there should be an attribute called 'connectionstyle', but just can't seem to get it working.