Matplotlib mapping toolkit - help

Ale� �ade� wrote:

Dear Jeffrey,

First of all, sorry to bother you. I'm using matplotlib mapping toolkit. Can you help me with one problem. I would like to colour different countries with different colors. Is there any way to do this with basemap toolkit library? I just can't seem to find any function that would do that.

Thank you again,

Ales Cadez

Ales: You need an external shapefile containing country polygons for this. The built-in country dataset in Basemap is made up of line segments, so you can't fill them. Here's a simple example to get you started:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap as Basemap
from matplotlib.patches import Polygon

# Robinson world map
m = Basemap(projection='robin',lon_0=0)
# draw country boundaries
# data from
shp_info = m.readshapefile('world_adm0','countries',drawbounds=True)
ax = plt.gca() # get current axes instance
# fill US blue, Russia red, the rest gray.
for nshape,seg in enumerate(m.countries):
    if m.countries_info[nshape]['NAME'] == 'United States':
        poly = Polygon(seg,facecolor='b',edgecolor='b')
    elif m.countries_info[nshape]['NAME'] == 'Russia':
        poly = Polygon(seg,facecolor='r',edgecolor='r')
        poly = Polygon(seg,facecolor='0.7',edgecolor='0.7')
# draw meridians and parallels.
# draw projection limb, set background color
plt.title('US Blue, Russia Red')



Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328