In [17]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx

Build basic network


In [37]:
G = nx.DiGraph()
G.add_edge('A', 'B', weight=100)
G.add_edge('A', 'C', weight=200)
G.add_edge('C', 'D', weight=400)

In [24]:
# this uses a spring layout -- not very interesting
nx.draw_networkx(G)



In [13]:
from mpl_toolkits.basemap import Basemap

In [11]:
pos = dict(
    A = (-70,30),
    B = (-120,50),
    C = (20,40),
    D = (50,60)
)

Setup a basic map


In [32]:
m = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80,\
            llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='black',lake_color='CornflowerBlue')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='CornflowerBlue')


Out[32]:
<matplotlib.patches.Rectangle at 0x11b76bf50>

In [33]:
# convert to map coords
mpos = {}
for k,v in pos.iteritems():
    mpos[k] = m(*v)
mpos


Out[33]:
{'A': (11493790.311798483, 17873840.80843375),
 'B': (6269340.1700719, 20636003.147698984),
 'C': (20897800.566906333, 19152637.77464683),
 'D': (24032470.651942283, 22469602.098788254)}

In [40]:
m = Basemap(projection='merc',llcrnrlat=-80,urcrnrlat=80,\
            llcrnrlon=-180,urcrnrlon=180,lat_ts=20,resolution='c')
m.drawcoastlines()
m.fillcontinents(color='black',lake_color='CornflowerBlue', zorder=-2)  # had to fix this.
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='CornflowerBlue')

nx.draw_networkx(G, pos=mpos, edge_color='white')



In [ ]: