GEOSGeom

tech2022-07-17  183

今天小编在运行一段代码时,反复出现以下错误: GEOSGeom_createLinearRing_r returned a NULL pointer

经多方找寻资料未果后,于是选择了重启jupyter notebook,再次运行,问题便迎刃而解。目前还尚未知道为何这样,等待高人来给出答案。 下面给出例子:

import numpy as np import cartopy.crs as ccrs import cartopy.feature as cfeat from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER import matplotlib.pyplot as plt import matplotlib.ticker as mticker from netCDF4 import Dataset from cartopy.util import add_cyclic_point nc_file=Dataset('C:/Users/86132/sst.mon.mean.nc') lon=nc_file.variables['lon'][:]#读取经度 lat=nc_file.variables['lat'][:]#读取纬度 sst=nc_file.variables['sst'][0][:][:]#读取0时刻海温 fig = plt.figure(figsize=(8,6),dpi=500)#创建画板 ax=fig.add_subplot(1,1,1, projection=ccrs.PlateCarree()) ax.coastlines()#添加海岸线 ax.add_feature(cfeat.LAND)#添加陆地 gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.7, color='k', alpha=1, linestyle='--') gl.xlabels_top = False # 关闭顶端的经纬度标签 gl.ylabels_right = False # 关闭右侧的经纬度标签 gl.xformatter = LONGITUDE_FORMATTER # x轴设为经度的格式 gl.yformatter = LATITUDE_FORMATTER # y轴设为纬度的格式 gl.xlocator = mticker.FixedLocator(np.arange(-180, 180.1, 30)) gl.ylocator = mticker.FixedLocator(np.arange(-90,90.1, 30)) gl.xlines=False#关闭内部经纬线 gl.ylines=False#关闭内部经纬线 #################以下步骤添加数据循环,防止白条################## cycle_sst, cycle_lon = add_cyclic_point(sst, coord=lon) cycle_LON, cycle_LAT = np.meshgrid(cycle_lon, lat) ax.contourf(cycle_LON,cycle_LAT, cycle_sst,levels=np.arange(-10,35),cmap='RdBu_r') plt.savefig('海温场',bbox_inches='tight') plt.show()

最新回复(0)