2013-12-20 52 views
2

我正在使用matplotlib底圖來繪製美國大陸的地圖。有沒有辦法將海岸線/國家邊界過濾到美國?作爲加拿大我通常不喜歡加拿大排除在外,但想在這種情況下:-)如何將matplotlib底圖邊界數據過濾到特定的國家或州?

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() 

回答

5

你可能想看看Cartopy代替。底圖主要關注地球的不同地圖投影,而Cartopy可以使用shapereader使用NaturalEarthData數據集中的任意地圖。退房this example顯示在美國大陸卡特里娜颶風的路徑:

katrina

+0

是的,這看起來很有趣。我希望在[D3js]中使用像'countries.features.filter()'或'topojson.mesh(...,filter)'成語的東西(https://github.com/mbostock/topojson/wiki/API -Reference),以便在我調用'm.drawxxx()'之前修剪邊界 – patricksurry