[Matplotlib-users] Basemap and counties

Benjamin Root ben.root at ou.edu
Wed Aug 19 18:36:48 CEST 2015


On Wed, Aug 19, 2015 at 11:07 AM, Tommy Grav <tgrav at me.com> wrote:

> from mpl_toolkits.basemap import Basemap
> import matplotlib.pyplot as plt
> import numpy as np
>
> # make sure the value of resolution is a lowercase L,
> #  for 'low', not a numeral 1
> map = Basemap(projection='merc', lat_0=39.1622, lon_0=-86.5292,
>    resolution = 'h', area_thresh = 0.1,
>    llcrnrlon=-88.53, llcrnrlat=37.16,
>    urcrnrlon=-84.53, urcrnrlat=41.16)
>
> map.drawcoastlines()
> map.drawcountries()
> map.drawstates(linewidth=0.5, linestyle="solid", color="r", antialiased=1,
> ax=None, zorder=None)
> map.drawcounties(linewidth=0.1,linestyle="solid", color="k", antialiased=1,
>                 ax=None, zorder=None, drawbounds=False)
> #map.fillcontinents(color='coral')
> map.drawmapboundary()
>
> map.drawmeridians(np.arange(0, 360, 30))
> map.drawparallels(np.arange(-90, 90, 30))
>
> plt.show()
>


You can set the "facecolor" of the counties when you call drawcounties().
The problem is getting only certain counties colored. That means you pass a
list of colors to "facecolor". The problem there is that you don't know the
order in which the counties are processed. I've done this before, but I
have to dig up that code... Maybe someone else can beat me to that?

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20150819/c2b833e3/attachment.html>


More information about the Matplotlib-users mailing list