python工具——basemap使用一基本使用

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

原文地址:https://www.cnblogs.com/baby123/p/14235758.html