今天记录分享一下Cartopy绘制世界地图展示监测站点的全球分布情况。
最终效果:
代码如下:
代码如下:
# -*- encoding: utf-8 -*-
'''
@File : PLOT_SITE.PY
@Time : 2022/02/28 13:42:59
@Author : HMX
@Version : 1.0
@Contact : kzdhb8023@163.com
'''
# here put the import lib
import time
import cartopy.crs as ccrs
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
def cm2inch(x,y):
return x/2.54,y/2.54
t1 = time.time()
size1 = 10.5
fontdict = {'weight': 'bold','size':size1,'family':'SimHei'}
mpl.rcParams.update(
{
'text.usetex': False,
'font.family': 'stixgeneral',
'mathtext.fontset': 'stix',
"font.family":'serif',
"font.size": size1,
"mathtext.fontset":'stix',
"font.serif": ['Times New Roman'],
}
)
# 构造数据
np.random.seed(7)
n = 100
x = np.random.randint(-170,170,n)
y = np.random.randint(-80,80,n)
# 绘制地图
proj=ccrs.PlateCarree()
fig,ax1 = plt.subplots(1, 1,figsize=cm2inch(16,9),dpi=100, subplot_kw={'projection': proj})
# ax1.stock_img()#自带的低分辨率的底图
# NASA官网下载的高分辨率底图(https://www.naturalearthdata.com/downloads/10m-raster-data/10m-cross-blend-hypso/)
ax1.imshow(plt.imread(r'E:\Project\World\NE1_LR_LC_SR_W_DR\NE1_LR_LC_SR_W_DR.tif')
, origin='upper', transform=ccrs.PlateCarree(), extent=[-180, 180, -90, 90])
ax1.coastlines()
ax1.set_xticks(np.arange(-180, 181, 60), crs = proj)
ax1.set_yticks(np.arange(-90, 91,30), crs = proj)
ax1.xaxis.set_major_formatter(LongitudeFormatter())
ax1.yaxis.set_major_formatter(LatitudeFormatter())
ax1.minorticks_on()
# 绘制监测站
ax1.scatter(x,y, marker='.' , s=25 , color = "k" , zorder = 3,label = '监测站')
plt.legend(prop = fontdict,loc= 'lower left')
plt.tight_layout()
plt.savefig(r'E:\Project\Figure\wwlln_sites2.png',dpi = 800)
t2 = time.time()
print('共计用时{:.2f}'.format(t2-t1))
plt.show()
如果对你有帮助的话,请‘点赞’、‘收藏’,‘关注’,你们的支持是我更新的动力。
欢迎关注公众号【森气笔记】。