码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Python绘制global mapping


    总结很好的资料,可参考:
    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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    报错: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()
    
    • 1
    • 2
    • 3
    • 4
    • 5

    结果:
    在这里插入图片描述
    pygmt绘制地图参数:
    (1)Projections:https://www.pygmt.org/latest/projections/index.html

    • Azimuthal Projections方位投影
    • Conic Projections圆锥投影
    • Cylindric Projections圆柱投影
    • Miscellaneous Projections
      在这里插入图片描述
      截取自:https://docs.gmt-china.org/latest/proj/
      比如自己想画一个这样的图:
      在这里插入图片描述

    选用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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    (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

    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
    
    • 1
    • 2

    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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    显示结果:
    在这里插入图片描述
    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")
    
    • 1

    设置属性:

    fig.plot(
        x=data.longitude,
        y=data.latitude,
        size=0.02 * (2**data.magnitude),
        style="cc",
        color="white",
        pen="black",
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    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()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

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

    (3)colobar设置
    https://www.pygmt.org/v0.1.1/gallery/plot/colorbar.html#:~:text=The%20pygmt.Figure.colorbar%20method%20creates%20a%20color%20scalebar.%20We,color%20paletted%20tables%20can%20be%20found%20at%20https%3A%2F%2Fdocs.generic-mapping-tools.org%2Flatest%2Fcookbook%2Fcpts.html.

    在这里插入图片描述
    Built-in color palette tables (CPT):https://docs.generic-mapping-tools.org/latest/cookbook/cpts.html
    在这里插入图片描述

  • 相关阅读:
    PyTorch 从tensor.grad 看 backward(权重参数) 和 gradient accumulated
    vue3笔记1
    高速,低延,任意频丨庚顿新一代实时数据库鼎力支撑电力装备服务数字化
    【Java PTA作业】当老师一口气布置八个作业( 5 / 8 )
    ES6中的基础知识点 — Promise
    html用css grid实现自适应四宫格放视频
    北航计算机软件技术基础课程作业&笔记【4】
    Flink系列之Flink之Time和WaterMark深入剖析
    【Unity实战】在RHEL 9上安装UnityHub
    一文带你了解人工智能:现状、应用、变革及未来展望
  • 原文地址:https://blog.csdn.net/qq_32649321/article/details/126008123
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号