总结很好的资料,可参考:
1.matlab绘制世界地图
使用工具:worldmap和geoshow和m_map
2.Python绘制地图PyGMT(Generic Mapping Tools (GMT)):https://www.pygmt.org/latest/
PyGMT教程:https://www.pygmt.org/latest/tutorials/index.html
GMT简介:
GMT全称是Generic Mapping Tools,是一个开源的地理绘图和笛卡尔数据集处理(包括滤波,趋势拟合,网格化,投影等)软件。
GMT为以下几种语言提供了API,方便它们直接调用GMT绘制图:MATLAB;Python; Fortran;Julia
GMT安装与教程:https://github.com/zhongpenggeo/GMT_demo
pygmt安装步骤(win10):
(1)创建一个新的环境:conda create -n name python=3.9;
(2)激活该环境:activate name
(3)安装pygmt:conda create --name pygmt --channel conda-forge pygmt

(4)测试import pygmt
import pygmt
fig = pygmt.Figure()
fig.plot(
region=[0, 10, 0, 10],
projection="X15c/10c",
frame="a",
x=[1, 8],
y=[5, 9],
pen="1p,black",
)
fig.show()
报错:AttributeError: partially initialized module 'pygmt' has no attribute 'Figure' (most likely due to a circular import)
报错原因:文件命名与包名相同,需要更改文件名。

运行结果:

绘制global mapping:
import pygmt
fig = pygmt.Figure()
fig.coast(shorelines="1/0.5p", region=[-180, 180, -60, 60], projection="M25c")
fig.basemap(frame="ag")
fig.show()
结果:

pygmt绘制地图参数:
(1)Projections:https://www.pygmt.org/latest/projections/index.html


选用Robinson投影(N12c)

代码:
import pygmt
fig = pygmt.Figure()
# Use region "d" to specify global region (-180/180/-90/90)
fig.coast(region="d", projection="N12c", land="goldenrod", water="snow2", frame="afg")
fig.show()
(2)显示图片:Figure.show(dpi=300, width=500, method=None, waiting=0.5)
https://www.pygmt.org/latest/api/generated/pygmt.Figure.show.html
如果可以的话,在Jupyter笔记本输出中插入预览,否则在操作系统的默认查看器中打开它(返回到默认的web浏览器)。
(3)pygmt.Figure.coast
Figure.coast(*, region=None, projection=None, area_thresh=None, lakes=None, frame=None, resolution=None, dcw=None, rivers=None, map_scale=None, borders=None, shorelines=None, land=None, water=None, timestamp=None, verbose=None, xshift=None, yshift=None, panel=None, perspective=None, transparency=None, **kwargs)
1)region
Global regions:region="d"
其他方式:region=[10, 20, 35, 45]# Set the x-range from 10E to 20E and the y-range to 35N to 45N;
region="10/35/20/45+r" # Set the bottom-left corner as 10E, 35N and the top-right corner as
# 20E, 45N
2)frame边框:fig.basemap(frame=["a", "+tIceland"])
https://www.pygmt.org/latest/tutorials/basics/frames.html
3.利用pygmt绘制beautiful map 例子
(1)Github上 Planetary Maps (in PyGMT)
代码:https://github.com/andrebelem/PlanetaryMaps/blob/main/Tutorial%20Mars%20Maps.ipynb
(2)使用GMT绘制地图
https://zhuanlan.zhihu.com/p/81292733
(3)PyGMT中文教程
https://docs.gmt-china.org/latest/api/python/
Github 相关项目:https://github.com/GenericMappingTools/pygmt
自带数据集:https://docs.gmt-china.org/latest/dataset/

代码:
import pygmt
# Load sample earth relief data
grid = pygmt.datasets.load_earth_relief(resolution="10m")
fig = pygmt.Figure()
fig.grdimage(grid=grid, projection="R12c",cmap="geo")
fig.show()
显示结果:

https://www.pygmt.org/latest/tutorials/advanced/earth_relief.html和https://docs.gmt-china.org/latest/dataset/earth-relief/结合起来学习,比较偏向利用Python写脚本。
自带数据集:GADM,全称Database of Global Administrative Areas,是一个高精度的全球行政区划数据库。其包含了全球所有国家和地区的国界、省界、市界、区界等多个级别的行政区划边界数据。
https://docs.gmt-china.org/latest/dataset/gadm/
4.pygmt学习笔记
(1)read shp file
安装geopandas环境:https://zhuanlan.zhihu.com/p/160252163
先激活环境查看Python版本:

(2)read csv data
fig.plot(x=data.lon, y=data.lat, style="c0.3c", color="white", pen="black")
设置属性:
fig.plot(
x=data.longitude,
y=data.latitude,
size=0.02 * (2**data.magnitude),
style="cc",
color="white",
pen="black",
)
fig = pygmt.Figure()
fig.basemap(region=region, projection="M15c", frame=True)
fig.coast(land="black", water="skyblue")
pygmt.makecpt(cmap="viridis", series=[data.depth_km.min(), data.depth_km.max()])
fig.plot(
x=data.longitude,
y=data.latitude,
size=0.02 * 2**data.magnitude,
color=data.depth_km,
cmap=True,
style="cc",
pen="black",
)
fig.colorbar(frame='af+l"Depth (km)"')
fig.show()

图片来自:https://www.pygmt.org/latest/tutorials/basics/plot.html#sphx-glr-tutorials-basics-plot-py
可以设置点的属性(大小、颜色、种类等)

Built-in color palette tables (CPT):https://docs.generic-mapping-tools.org/latest/cookbook/cpts.html
