我正试着用cartopy绘制北极的等高线。我使用了add_cyclic_point,它成功地填补了pcolormesh中本初子午线的空白,但轮廓并没有成功地交叉,而是包裹了整个地球进行连接(但似乎并不总是如此?)我的经度从0到360,我尝试切换到-180-180,但仍然得到相同的问题。
下面是我的代码:
import numpy as np
from netCDF4 import Dataset
import cartopy.crs as ccrs
import cartopy
from cartopy.util import add_cyclic_point as cycpt
import matplotlib.pyplot as plt
date = '2018_02_10'
pdatafile = Dataset(date+'_mslp.nc')
plat = np.array(pdatafile.variables['lat'])
plon = np.array(pdatafile.variables['lon'])
p = np.array(pdatafile.variables['slp'][0,:,:])
p_cyclic,lon_cyclic = cycpt(p,coord=plon)
lon_cyclic = np.ma.getdata(lon_cyclic)
plon2d,plat2d= np.meshgrid(lon_cyclic,plat)
p_cyclic = np.ma.getdata(p_cyclic)
g1000datafile = Dataset(date+'_1000mb_gph.nc')
g1lat = np.array(g1000datafile.variables['lat'])
g1lon = np.array(g1000datafile.variables['lon'])
g1000 = np.array(g1000datafile.variables['hgt'][0,0,:,:])
g1_cyclic,g1lon_cyclic = cycpt(g1000,coord=g1lon)
g1lon2d,g1lat2d= np.meshgrid(g1lon_cyclic,g1lat)
g1lon2d = np.ma.getdata(g1lon2d)
g1_cyclic = np.ma.getdata(g1_cyclic)
g500datafile = Dataset(date+'_500mb_gph.nc')
g5lat = np.array(g500datafile.variables['lat'])
g5lon = np.array(g500datafile.variables['lon'])
g500 = np.array(g500datafile.variables['hgt'][0,0,:,:])
g5_cyclic,g5lon_cyclic = cycpt(g500,coord=g5lon)
g5lon2d,g5lat2d= np.meshgrid(g5lon_cyclic,g5lat)
g5lon2d = np.ma.getdata(g5lon2d)
g5_cyclic = np.ma.getdata(g5_cyclic)
thickness = g5_cyclic - g1_cyclic
mslplevels=[960,970,980,990,1000,1010,1020,1030,1040,1050]
levels500hPa = [470,480,490,500,510,520,530,540,550,560]
ax = plt.axes(projection=ccrs.NorthPolarStereo(central_longitude=0))
ax.set_extent([-180, 180, 50, 90], crs=ccrs.PlateCarree())
plt.pcolormesh(plon2d,plat2d,thickness/10, transform=ccrs.PlateCarre(),cmap='inferno')
cbar=plt.colorbar()
cbar.set_label('ReTop (gpdam)')
cs=plt.contour(plon2d,plat2d,g5_cyclic/10,colors='w',transform=ccrs.PlateCarree(),\
levels=levels500hPa)
plt.clabel(cs,inline=1,fontsize=6,fmt='%3.0f')
ax.coastlines()
plt.show()
plt.close()import numpy as np
from netCDF4 import Dataset
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point as cycpt
import matplotlib.pyplot as plt
pdatafile = Dataset('X158.39.88.89.59.7.59.32.nc')
plat = np.array(pdatafile.variables['lat'])
plon = np.array(pdatafile.variables['lon'])
p = np.array(pdatafile.variables['slp'][0,:,:])
p_cyclic,lon_cyclic = cycpt(p,coord=plon)
lon_cyclic = np.ma.getdata(lon_cyclic)
p_cyclic = np.ma.getdata(p_cyclic)
plon2d,plat2d= np.meshgrid(lon_cyclic,plat)
ax = plt.axes(projection=ccrs.NorthPolarStereo(central_longitude=0))
ax.set_extent([-180, 180, 50, 90], crs=ccrs.PlateCarree())
plt.contour(plon2d,plat2d,g5_cyclic/10,colors='w',transform=ccrs.PlateCarree())
plt.clabel(cs,inline=1,fontsize=6,fmt='%3.0f')
ax.coastlines()
plt.show()ftp://ftp.cdc.noaa.gov/Public/www/X158.39.88.89.59.7.59.32.nc
发布于 2018-03-02 04:37:19
我怀疑问题与等高线标签有关,众所周知,等高线标签在Cartopy中不能很好地工作(参见https://github.com/SciTools/cartopy/issues/13和https://github.com/SciTools/cartopy/issues/327)。如果删除标签,则轮廓应正确渲染。
发布于 2018-03-01 22:33:25
我是cartopy开发人员,我想看看我能做些什么,但你的代码片段有点让人费解。如果我可以访问你的数据,那么它可能并不重要,但我不能,所以我不能运行或调试它。
你可以减少你的脚本,请到一个独立的或至少最小,无噪音和清晰的东西。谢谢。
另外,你的plot调用中有一个拼写错误,所以你的转换是PlateCarre而不是Platecarree。我不知道这会有多大的不同,但这是值得纠正的。
https://stackoverflow.com/questions/49048411
复制相似问题