美文网首页
PYGMT初体验

PYGMT初体验

作者: cugliming | 来源:发表于2021-07-12 21:59 被阅读0次

PYGMT是GMT的Python接口,可以直接在python环境下使用GMT。
项目主页Overview — PyGMT

import pygmt
import pandas as pd
import numpy as np
data = pd.read_csv("eqlist.csv") # 使用pandas读取数据
fig = pygmt.Figure()
fig.basemap(
    region=[101, 108, 33, 40],
    projection="M10c",
    frame=["xa2fg", "ya2fg", "WSrt"],
)
# 绘图
fig.plot(
    x = data.lon,
    y = data.lat,
    style = "cc",
    # size = np.where(data.m < 7, 0.1, 0.2), # 
    # 使用列表生成式,根据震级大小定义符号的大小
    size = [0.1 if x <7 else (0.2 if x < 8 else 0.3) for x in data.m],
    cmap = "cpt",
    # color = data.color, # 这种方式需要在数据中添加一列颜色的代码
    # 使用列表生成式,根据震级大小定义符号的大小;不需要再数据中添加一列
    color = [0 if x < 7 else (1 if x < 8 else 2) for x in data.m ],
    pen = "0.2p,black"
)
fig.savefig("test.png", dpi=600)

绘图如下:


震中分布

相关文章

网友评论

      本文标题:PYGMT初体验

      本文链接:https://www.haomeiwen.com/subject/ozbdpltx.html