I am trying to plot my Network Graph, produced with NetworkX over a Basemap - following the logic of this example. My netowkr will plot separately but when I run the code below I am just given the basemap with no nodes or edges having been plotted.
lat = np.asarray(list(stations['latitude']))
lon = np.asarray(list(stations['longitude']))
plt.figure(figsize = (10,9))
m = Basemap(llcrnrlon=lon_min, llcrnrlat=lat_min, urcrnrlon=lon_max, urcrnrlat=lat_max,
#lat_0=(lat_max - lat_min)/2,
#lon_0=(lon_max - lon_min)/2,
projection='merc',
resolution = 'f',)
mx, my = m(stations['latitude'].values, stations['longitude'].values)
pos = {}
for count, elem in enumerate (stations['station']):
pos[elem] = (mx[count], my[count])
nx.draw_networkx_nodes(G = graph, pos = pos, nodelist = graph.nodes(),
#node_color = carac['counts'],
alpha = 0.8,
#node_size = carac['counts']/5
)
nx.draw_networkx_edges(G = graph, pos = pos, edge_color='g',
alpha=0.2, arrows = False,
#width=list(widths.values())
)
m.drawcoastlines()
m.drawstates()
m.fillcontinents(lake_color='cornflowerblue')
m.drawmapboundary(fill_color='royalblue')
m.drawrivers()
plt.tight_layout()
plt.show()
I have looked at previous answers here such as this but cannot find an obvious answer as to what i'm doing wrong.
One thing I do notice is mx and my array that are produced on line 9 do not list the actual long/lat coordinates as per my stations df. However I suspect this could be a red herring as if i run mx, my = m(np.asarray(list(stations['latitude'], np.asarray(list(stations['longitude'])instead i get the same results for mx, my.
UPDATE: I have switched the 'mx, my =' function to plot by longitude first:
`mx, my = m(stations['latitude'].values, stations['longitude'].values)`
This has brought my nodes onto the map, although the edges between the nodes are still non-existent.