外链论坛

 找回密码
 立即注册
搜索
查看: 5|回复: 0

教程合集 | Python绘制地图

[复制链接]

2826

主题

1万

回帖

9956万

积分

论坛元老

Rank: 8Rank: 8

积分
99569756
发表于 2024-10-10 08:43:20 | 显示全部楼层 |阅读模式

嘟嘟嘟,本期校车在周一和大众准时见面啦!地图绘制的最后一期鲜嫩出炉~本期将对Python地图绘制进行说明。在将来的一段日子里,本栏目将延续从一个问题出发,用多个语言来处理的风格,每期更新2~3门语言不等,平均3上下更新完一个专题,各位心急的小伙伴能够先去家园挖掘宝藏!

在Python中,重点运用的地图可视化工具包是Cartopy、Basemap、Geopandas等。Geopandas由于是最新显现的一个库,在家园里几乎讨论度。Basemap随着Python2的停止更新逐步会淡出人们的视野(版本管理大神请忽略此条)。家园日前热度最高的还要数英国气象局研发的Cartopy可视化库。

当然,在画图行业,最不可忽略的便是Matplotlib库,在本期中不做重点介绍,后期数据可视化部分再介绍~

Cartopy

Cartopy库在这三个库中持有着最高的人气,画图时,设置项目语句虽然略微繁琐,然则不怕,一众能手早已铺好前路,既有汉化版教程,又有热情大神答疑,反而作为运用时体验感最佳的一个库。#加载库import matplotlib.pyplot as pltimport cartopy.crs as ccrsimport cartopy.io.shapereader as shpreaderimport numpy as npfigure = plt.figure()#加载画布china = plt.axes(projection=ccrs.PlateCarree())#设置投影方式chinamap = shpreader.Reader(bou2_4l.shp).geometries()#读取地图数据china.set_extent([70,140,15,55], crs=ccrs.PlateCarree())#设置绘图范围china.add_geometries(chinamap, ccrs.PlateCarree(),facecolor=none, edgecolor=black)#设置边界样式my_x_ticks = np.arange(70, 150, 10)my_y_ticks = np.arange(15, 65, 10)#重视数据集合左闭右开的特征china.set_xticks(my_x_ticks,crs=ccrs.PlateCarree())china.set_yticks(my_y_ticks,crs=ccrs.PlateCarree())#设置坐标标签plt.show()

奋斗之后得到一张图:

家园论坛中可谓是群英荟萃,各显神通,快来一块瞧瞧吧~

Cartopy快速安装:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=36761

Cartopy安装手册 ——零基本Python的安装教育(by:不想去气象局)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=96415

Cartopy 简单入门教程(by:灭火器)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=92502

Python绘图利器Cartopy中文介绍:(by:junyang517) https://bbs.06climate.com/forum.php?mod=viewthread&tid=69269

Cartopy官网例程大全(中文翻译版):(by:qazwsxpy)

http://bbs.06climate.com/forum.php?mod=viewthread&tid=96749

[原创]Python绘制地图的利器Cartopy运用说明(by:阿阿飞飞)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=33601

Cartopy学习笔记:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=58960

Python气象绘图教程:(by:笺疏)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=95948

Cartopy 下站点资料画图及白化:(by:chiqu296)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=93995

介绍一种Cartopy绘图白化的办法(by:po_po1)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=24966

加强白化效率(by:veir)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=96578

Cartopy绘制极射赤面投影:(by:wxj96)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=93177

 [求助]Cartopy设置经纬度范围:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=92138

[求助]Cartopy Contourf画图经纬度问题:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=96297

Python Matplotlib Cartopy学习笔记-练习2:(by:JOJOweibo)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=58970

CartoPy画色斑图的时候没法同期表示地图和数据:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=66849

一套适用大气专业的Python编程经验:(by:biubiubiu123)

http://bbs.06climate.com/forum.php?mod=viewthread&tid=94639

Basemap

因为Basemap库只能在Python2的环境下运行,因此呢小伙伴们运用之前千万要重视改到Python2而不是Python3下运行,家园里就有非常多小伙伴四处询问:为何我装不上这个库,是不是电脑有问题?NoNoNo,你可能只是忘记更改运行环境啦!

博主的电脑在切换版本的时候提示连接有问题T_T,只好此处给出家园里大佬xiuyuanyang的示例:https://bbs.06climate.com/forum.php?mod=viewthread&tid=51427

该帖子中画图关联有些关键代码如下:

#加载库frommpl_toolkits.basemapimport Basemapimport matplotlib.pyplot as pltimport numpy as npmap.drawcoastlines() #画海岸线map.drawcountries() #画国界线map.drawcounties() #画县界限map.readshapefile("D:\\GoogleDownload\\CHN_adm_shp\\CHN_adm1",states,drawbounds=True)#读取地图数据map.drawmapboundary()#画中国内部区域,即省界线parallels = np.arange(0.,90,10.#创建纬线数组map.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)# 绘制纬线meridians = np.arange(80.,140.,10.#创建经线数组map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)# 绘制经线plt.show()

xiuyuanyang给出的示例如下图,欢迎各位移步论坛贴子中交流~

Python的Basemap安装总结(by:lm8005507771)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=94118

绘制地图库Basemap的安装与运用

https://bbs.06climate.com/forum.php?mod=viewthread&tid=53565

Python之地理信息可视化——Matplot Basemap工具箱:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=10010

Basemap Tutorial Documentation 官方文档翻译:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=92263

重磅推出,利用Matplotlib和Basemap绘制Micaps数据:(by:非对叫作

https://bbs.06climate.com/forum.php?mod=viewthread&tid=51944

我的Python学习第二步:绘制基本图形,查看某个模块是不是存在?Basemapde 基本运用(by:Swallow)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=47361

Python完美白化(by:平流层的萝卜)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=42437

针对上贴,不思虑地图shapes中utf-8编码,直接读取shapefile只绘制陆地色斑:(by:_丢丢_)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=93734

Python画地图怎么添加指北针以及比例尺:

https://bbs.06climate.com/forum.php?mod=viewthread&tid=96282

Basemap保留的带省界的svg格式照片出错(溢出),用自己生成的省边界数据画图:(by:18393810639)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=91319

Python 读取Micaps第14类数据,并用Basemap进行绘图:(by:18393810639)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=90319

Ubuntu+Anaconda+Python+Basemap(+WRF)总结:(by:8828) https://bbs.06climate.com/forum.php?mod=viewthread&tid=49137

Python绘制全世界地形和中国地形:(by:Masterpiece)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=95503

利用Python画中国地图外加站点分布:(by:xiuyuanyang)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=51427

Geopandas

Geopandas的讨论在家园日前处在神隐状态,朋友们,作为开山版主的大好机会这不就来了吗!

欢迎大众前往论坛多多交流,同期在学习的过程中可先去官网自动探索:https://geopandas.org/

这儿给出一个简单的利用Geopandas做可视化的例子:

import geopandas as gpimport matplotlib.pyplot asplt#加载库包shps = gp.read_file(bou1_4l.shp)#读取地图shapefile文件m_china = shps.cx[70:140,10:60]#设置读取地图数据范围m_china.plot()#利用matplotlib画图plt.xlim((70, 140))plt.ylim((10, 60))#设置x,y轴范围,否则geopandas边线会默认留白

如此如此,这般这般之后,就得到如下一张图:

是不是超级简单超级方便!日前家园针对geopandas库的讨论还很少,欢迎各位能手来安利或拔草。

其它

欢迎大众前往论坛多多挖掘宝藏教程~                                                                         

Python绘制中国精确地图:(by:yang69can)

https://bbs.06climate.com/forum.php?mod=viewthread&tid=48590

Python3.GDAL从shp文件生成mask:(by:墨家小宝)

http://bbs.06climate.com/forum.php?mod=viewthread&tid=6366

本期内容到此结束!有什么疑问?文中内容有错误或遗漏?

欢迎移步气象家园论坛:

http://bbs.06climate.com/

有什么问题,咱们一块来讨论处理~

编辑:星星伴月 知名不具的弹棉花手

教程资源均来自气象家园论坛用户

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

站点统计|Archiver|手机版|小黑屋|外链论坛 ( 非经营性网站 )|网站地图

GMT+8, 2024-10-18 22:28 , Processed in 0.062490 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.