In [17]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
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)
)
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]:
In [33]:
# convert to map coords
mpos = {}
for k,v in pos.iteritems():
mpos[k] = m(*v)
mpos
Out[33]:
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 [ ]: