basemap基於GEOS的地圖二維數據,其底圖數據庫與GMT相同,封裝了大量常用的地圖投影、坐標轉換功能,利用簡潔的Python語法支持繪出多種多樣的地理地圖
1.安裝
基於geos的,先安裝geos
pip install geos
https://www.lfd.uci.edu/~gohlke/pythonlibs/ 下載
basemap-1.2.2-cp37-cp37m-win_amd64.whl
注:
cp后面的數字是Python的版本,根據自己的python版本來
安裝
pip install basemap-1.2.2-cp37-cp37m-win_amd64.whl --default-timeout=200
eg:
繪制最簡單的地圖
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt map = Basemap() map.drawcoastlines() plt.show() plt.savefig('test.png')
可以給陸地和海洋填上不同的顏色
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt map = Basemap(projection='ortho', lat_0=0, lon_0=0) #Fill the globe with a blue color map.drawmapboundary(fill_color='aqua') #Fill the continents with the land color map.fillcontinents(color='coral',lake_color='aqua') map.drawcoastlines() plt.show()
繪制國家邊界
from mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt map = Basemap(projection='ortho', lat_0=0, lon_0=0) map.drawmapboundary(fill_color='aqua') map.fillcontinents(color='coral',lake_color='aqua') map.drawcountries() plt.show()
官網
https://basemaptutorial.readthedocs.io/en/latest/first_map.html