我目前正在从netcdf数据集中绘制降水。当我绘制数据时,会出现一条没有数据的行,这并不是我所做的另一次绘制。这是我的代码:
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np
from cartopy import config
import cartopy.crs as ccrs
fig = plt.figure(figsize=(20,5))
dataset = netcdf_dataset(datapath_1 +
'/PREC.E_2000_CAM5_1850aero.cam.mean.40-100.nc')
precip = dataset.variables['PREC'][0, :, :]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
ax = plt.axes(projection=ccrs.Robinson())
ax.contourf(lons, lats, precip, 100, transform=ccrs.PlateCarree())
ax.coastlines()
plt.show()
,这是输出映射: output map
答案 0 :(得分:1)
您可能需要在数据数组和经度坐标(https://scitools.org.uk/cartopy/docs/v0.16/cartopy/util/util.html#cartopy.util.add_cyclic_point)上添加一个循环点。您的示例已进行了修改,以实现此目的(但由于我们没有您的输入数据,因此未进行测试):
import matplotlib.pyplot as plt
from netCDF4 import Dataset as netcdf_dataset
import numpy as np
from cartopy import config
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point
dataset = netcdf_dataset(datapath_1 +
'/PREC.E_2000_CAM5_1850aero.cam.mean.40-100.nc')
precip = dataset.variables['PREC'][0, :, :]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]
precip_c, lons_c = add_cyclic_point(precip, coord=lons)
fig = plt.figure(figsize=(20,5))
ax = plt.axes(projection=ccrs.Robinson())
ax.contourf(lons_c, lats, precip_c, 100, transform=ccrs.PlateCarree())
ax.coastlines()
plt.show()