def plotLocationGraphOnMap(graph): points = map(lambda lid:getLocationFromLid(lid.replace('_', ' ')), graph.nodes()) _, m =plotPointsOnUSMap(points, s=10, lw=0, c='m', returnBaseMapObject=True) print graph.number_of_edges(), graph.number_of_nodes() totalEdgeWeight = max([d['w'] for _,_,d in graph.edges(data=True)])+0.0 for u, v, data in graph.edges(data=True): u, v, w = getLocationFromLid(u.replace('_', ' ')), getLocationFromLid(v.replace('_', ' ')), data['w'] m.drawgreatcircle(u[1],u[0],v[1],v[0],color=cm.Purples(w/totalEdgeWeight), alpha=0.5) plt.show()
def plotLocationClustersOnMap(graph): noOfClusters, clusters = clusterUsingAffinityPropagation(graph) nodeToClusterIdMap = dict(clusters) colorMap = dict([(i, GeneralMethods.getRandomColor()) for i in range(noOfClusters)]) clusters = [(c, list(l)) for c, l in groupby(sorted(clusters, key=itemgetter(1)), key=itemgetter(1))] points, colors = zip(*map(lambda l: (getLocationFromLid(l.replace('_', ' ')), colorMap[nodeToClusterIdMap[l]]), graph.nodes())) _, m =plotPointsOnUSMap(points, s=0, lw=0, c=colors, returnBaseMapObject=True) for u, v, data in graph.edges(data=True): if nodeToClusterIdMap[u]==nodeToClusterIdMap[v]: color, u, v, w = colorMap[nodeToClusterIdMap[u]], getLocationFromLid(u.replace('_', ' ')), getLocationFromLid(v.replace('_', ' ')), data['w'] m.drawgreatcircle(u[1],u[0],v[1],v[0],color=color, alpha=0.5) plt.show()