Menu

[r4677]: / trunk / toolkits / basemap / examples / plotcities.py  Maximize  Restore  History

Download this file

25 lines (22 with data), 677 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import pylab as p
from matplotlib.mlab import prctile_rank
import numpy
from matplotlib.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(p.cm.jet(float(rank)/100.))
m.drawcoastlines()
m.fillcontinents()
m.scatter(x,y,25,colors,marker='o',faceted=False,zorder=10)
p.title('City Locations colored by Population Rank')
p.show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.