资料的下载在上一篇中,
话不多说直接上程序(第一次用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站很多,这就不介绍了
结果图:
最后祝大家中秋国庆快乐!!!