0

I am trying to plot a warehouse location data using networkx. My sample dataset is as follows,

src_node dest_node src_edge dest_edge src_lat-src_lon dest_lat-dest_lon
1 3 a x 38.89-77.03 38.91-77.05
3 2 b y 38.91-77.05 38.82-77.01
4 1 c z 38.93-77.06 38.89-77.03

I tried this:

import network as nx
import matplotlib.pyplot as plt

data = [[1, 3, 'a', 'x', '38.89-77.03', '38.91-77.05'],[3, 2, 'b', 'y', '38.91-77.05', '38.82-77.01'],[4, 1, 'c', 'z', '38.93-77.06', '38.89-77.03']]
temp = pd.DataFrame(data, columns=['src_node', 'dest_node','src_edge','dest_edge','src_lat-src_lon', 'dest_lat-dest_lon'])


def plot_graph(nodes, edges, labels=False, node_size=False, node_color='r'):    
    plt.figure(figsize=(10,10))
    G = nx.DiGraph()
    G.add_nodes_from(nodes)
    G.add_edges_from(edges)
    nx.draw(G, with_labels=labels, node_color=node_color)
    plt.show()

plot_graph(nodes=pd.unique(temp['src_node'].append(temp['dest_node'])),
           edges=[tuple(row) for row in temp[['src_node','dest_node']].values],
           labels=True,
           node_color='orange')

enter image description here

However, i could only plot the nodes. i want to arrange these according to the lat and long values in the map and how to name the starting of the arrow with "src_edge" and exit of the arrow as "dest_edge". I want the plot for analyzing the neighbor relation and i am new to networkx, appreciate if i can get some help. thanks.

skiddy
  • 13
  • 3
  • Why having `src_edge` and `dest_edge` while `src_node and dest_node` are sufficient to define a graph? – swatchai Dec 18 '22 at 11:45
  • @swatchai `src_edge` and `dest_edge` are nothing but ports of the `src_node` and `dest_node`, so actually speaking i need `src_node + src_edge(src_port)` connection to the `dest_node + dest_edge(dest_port)` how can i do this? – skiddy Dec 19 '22 at 15:03

0 Answers0