地图的某些区域仍未着色

时间:2019-06-29 12:22:55

标签: python-3.x matplotlib-basemap netcdf4

我正在尝试绘制指定区域的地球地图。

地图的某些区域仍未着色的问题,即白色补丁出现在地图中。我不知道为什么会这样。

import os
os.environ['PROJ_LIB'] = r'C:\Users\harsh\Anaconda3\pkgs\proj4-5.2.0-h6538335_1003\Library\share'
import netCDF4 as nc
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors as c
from mpl_toolkits.basemap import Basemap,shiftgrid

#specify the path of you netCDF file
vc_open=nc.Dataset(r'C:\Users\harsh\Desktop\ARIES\pv.nc')

lt=vc_open.variables['latitude'][:]
ln=vc_open.variables['longitude'][:]
a=[float(i) for i in ln]
pv=(vc_open.variables['pv'][:])
time=vc_open.variables['time']
dates = nc.num2date(time[:],units=time.units,calendar=time.calendar)
lon1=-40
lon2=70
lat1=10
lat2=70
 font = {'family': 'serif',
        'color':  'darkred',
        'weight': 'bold',
        'size': 16,
        }
for i in range(1):
  fig= plt.figure(figsize=(20,10),dpi=100)
  ax = fig.add_subplot(1, 1, 1)  # specify (nrows, ncols, axnum)
  ax.set_title("Pv on %s"%dates[i],fontdict=font)

  m=Basemap(projection='mill',llcrnrlat=lat1,urcrnrlat=lat2, 
  llcrnrlon=lon1,urcrnrlon=lon2,resolution='i') 
  m.drawmapboundary()
  m.drawmeridians(np.arange(-180,180,15),labels=[0,0,0,1],fontdict=font)
  m.drawparallels(np.arange(-90,90,15),labels=[1,0,0,0],fontdict=font)

  pv,ln = shiftgrid(180.,pv,ln,start=False)
  llons, llats = np.meshgrid(ln, lt)
  x,y = m(llons,llats)
  data=(pv[i,:,:])
  data=data/0.000001

  cmap = c.ListedColormap(['#0000b3','#0000e6','#0026ff','#004cff',                           

'#ffff00','#ffe600','#ffcc00','#ffb300','#ff9900','#ff8000','#ff6600',
                         '#ff4c00','#ff2600','#e60000','#b30000','#800000','#4c0000']) 

   bounds=np.arange(0,2,0.105266316) 
  norm = c.BoundaryNorm(bounds, ncolors=cmap.N) # cmap.N gives the number of colors of your palette
  cs=m.contourf(x,y,data,15,cmap=cmap, norm=norm, levels=bounds,shading='interp')
   cbar=m.colorbar(cs, cmap=cmap, norm=norm, boundaries=bounds,ticks=bounds,ax=ax)
  cbar.set_label("pv %s"% vc_open.variables['pv'].units,fontdict=font)

plt.show()  

输出在这里:

enter image description here

netcdf文件的链接为here。 有人可以告诉我如何改善地图,从而使图表更平滑。

0 个答案:

没有答案