I have a pandas data frame with two columns: source and sink. In a simplified form, there are just 5 users (source column) that can owe money to any other user (sink column).
I thought the following code would show the plot of user 1 owing to user 3 (yes arrow is correct, good), user 2 to 4 (good), 3 to 5 (good), 4 to 1 (wrong), 5 to 2 (wrong). What should I do to get the last two arrows to point in the right direction?
<code>df = pd.DataFrame({'source': [1, 2, 3, 4, 5], 'sink': [3, 4, 5, 1, 2]})
G = nx.Graph()
for row in df.iterrows():
print(row[1]['source'], row[1]['sink'])
G.add_edge(row[1]['source'], row[1]['sink'])
# nx.draw(G, with_labels=True, font_weight='bold')
pos = nx.spring_layout(G)
nodes = nx.draw_networkx_nodes(G, pos, node_color="orange")
nx.draw_networkx_labels(G, pos)
edges = nx.draw_networkx_edges(
G,
pos,
arrows=True,
arrowstyle="->",
arrowsize=10,
width=2,
)
</code>
<code>df = pd.DataFrame({'source': [1, 2, 3, 4, 5], 'sink': [3, 4, 5, 1, 2]})
G = nx.Graph()
for row in df.iterrows():
print(row[1]['source'], row[1]['sink'])
G.add_edge(row[1]['source'], row[1]['sink'])
# nx.draw(G, with_labels=True, font_weight='bold')
pos = nx.spring_layout(G)
nodes = nx.draw_networkx_nodes(G, pos, node_color="orange")
nx.draw_networkx_labels(G, pos)
edges = nx.draw_networkx_edges(
G,
pos,
arrows=True,
arrowstyle="->",
arrowsize=10,
width=2,
)
</code>
df = pd.DataFrame({'source': [1, 2, 3, 4, 5], 'sink': [3, 4, 5, 1, 2]})
G = nx.Graph()
for row in df.iterrows():
print(row[1]['source'], row[1]['sink'])
G.add_edge(row[1]['source'], row[1]['sink'])
# nx.draw(G, with_labels=True, font_weight='bold')
pos = nx.spring_layout(G)
nodes = nx.draw_networkx_nodes(G, pos, node_color="orange")
nx.draw_networkx_labels(G, pos)
edges = nx.draw_networkx_edges(
G,
pos,
arrows=True,
arrowstyle="->",
arrowsize=10,
width=2,
)