import pandas as pd filename = '../chapter3/data/worldcitiespop.txt' data = pd.read_csv(filename) plot(data.Longitude, data.Latitude, ',') locations = data[['Longitude','Latitude']].as_matrix() from mpl_toolkits.basemap import Basemap m = Basemap(projection='mill', llcrnrlat=-65, urcrnrlat=85, llcrnrlon=-180, urcrnrlon=180) x0, y0 = m(-180, -65) x1, y1 = m(180, 85) population = data.Population x, y = m(locations[:,0], locations[:,1]) weights = population.copy() weights[isnan(weights)] = 1000 h, _, _ = histogram2d(x, y, bins=(linspace(x0, x1, 500), linspace(y0, y1, 500)), weights=weights) h[h==0] = 1 import scipy.ndimage.filters z = scipy.ndimage.filters.gaussian_filter(log(h.T), 1) figure(figsize=(10,6)) m.drawcoastlines() m.imshow(z, origin='lower', extent=[x0,x1,y0,y1], cmap=get_cmap('Reds'))