Python,利用GEBCO数据画海拔分布图

资料的下载在上一篇中,

话不多说直接上程序(第一次用python画图,仅供参考)

import numpy as np
import xarray as xr
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt#改变图片显示模式
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
f=xr.open_dataset('gebco_2023_n65.0_s50.0_w160.0_e200.0.nc')
#读取数据
lon=f['lon']
lat=f['lat']
z=f['elevation']
#开始画图并选定地图投影方式,此处纬度较高所以选用PlateCarre,低纬度可以用麦卡托投影
fig=plt.figure(figsize=(18,14))
ax1=fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(central_longitude=180))
ax1.coastlines()#画岸线
#设置横纵坐标刻度、显示方式和label
ax1.set_xticks(np.arange(160,200,10),crs=ccrs.PlateCarree())
ax1.set_yticks(np.arange(50,70,5),crs=ccrs.PlateCarree())
ax1.set_xlabel('longitude',fontsize=14)
ax1.set_ylabel('latitude',fontsize=14)
ax1.xaxis.set_major_formatter(cticker.LongitudeFormatter())
ax1.yaxis.set_major_formatter(cticker.LatitudeFormatter())
c1=ax1.contourf(lon,lat,z,levels=np.arange(-8000,5000,1000),extend='both',transform=ccrs.PlateCarree())#等值线填充图
ax1.set_title('Elevation distribution in the Bering Sea',fontsize=17)#标题
colorbar=fig.colorbar(c1,ax=ax1,label='elevation')#设置colorbar
plt.savefig('./py.png',dpi=400)#以‘py’为名字保留png图片到当前文件夹

这里要用到numpy、 xarray、matplotlib、cartopy等函数包,安装步骤C站很多,这就不介绍了

结果图:262843e33eda4e6cb89eb3d69c2eac4b.png

最后祝大家中秋国庆快乐!!!

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿翔_ocean

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值