File: plotcities.py

package info (click to toggle)
basemap 1.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 213,084 kB
  • sloc: ansic: 14,746; python: 9,847; sh: 1,961; makefile: 42
file content (23 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from matplotlib.mlab import prctile_rank
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap

# cities colored by population rank.

m = Basemap()
shp_info = m.readshapefile('cities','cities')
x, y = zip(*m.cities)
pop = []
for item in m.cities_info:
    population = item['POPULATION']
    if population < 0: continue # population missing
    pop.append(population)
popranks = prctile_rank(pop,100)
colors = []
for rank in popranks:
    colors.append(plt.cm.jet(float(rank)/100.))
m.drawcoastlines()
m.fillcontinents()
m.scatter(x,y,25,colors,marker='o',edgecolors='none',zorder=10)
plt.title('City Locations colored by Population Rank')
plt.show()