patricksurry
patricksurry

Reputation: 5878

How can I filter matplotlib basemap boundary data to specific countries or states?

I'm using matplotlib basemap to draw a map of the continental US. Is there some way to filter the coastline/country boundaries to just the US? Being Canadian I don't normally like to exclude Canada but would like to in this instance :-)

from mpl_toolkits.basemap import Basemap

plt.figure(figsize=(10,6))
m = Basemap(width=5e6,height=3e6,projection='laea',
        resolution='c',lat_0=39, lon_0=-96)
m.drawcoastlines(color="grey")
m.drawcountries(color="grey")
m.drawstates(color="grey")

plt.show()

Upvotes: 4

Views: 2112

Answers (1)

MattDMo
MattDMo

Reputation: 102862

You might want to check out Cartopy instead. Basemap is mainly concerned with different map projections of the Earth, while Cartopy has the ability to use arbitrary maps from the NaturalEarthData datasets using the shapereader. Check out this example showing Hurricane Katrina's path over the continental US:

katrina

Upvotes: 6

Related Questions