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 http://www.cipotato.org/diva/data/misc/world_adm0.zip
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')
    else:
        poly = Polygon(seg,facecolor='0.7',edgecolor='0.7')
    ax.add_patch(poly)
# draw meridians and parallels.
m.drawparallels(np.arange(-80,81,20))
m.drawmeridians(np.arange(-180,180,60))
# draw projection limb, set background color
m.drawmapboundary(fill_color='aqua')
plt.title('US Blue, Russia Red')
plt.show()


-Jeff

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


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to