netcdf - How to plot smooth line in python? -
ncep data website. want plot picture this:
or one(this 1 add trough lines): 
my data different them, content different. but, method should same.
i dont't know how smooth line. result: 
here code:
import numpy np import scipy import matplotlib.pyplot plt netcdf4 import dataset scipy.interpolate import rbf scipy.ndimage import zoom mpl_toolkits.basemap import basemap m=basemap(projection='cyl',llcrnrlat=20,urcrnrlat=50,llcrnrlon=90,urcrnrlon=130) chnshp = 'd:\python\shapefile\data\chn_adm_shp\chn_adm1' m.readshapefile(chnshp,'chn',drawbounds = false) twnshp = 'd:\python\shapefile\data\twn_adm_shp\twn_adm0' m.readshapefile(twnshp,'twn',drawbounds = false) info, shape in zip(m.chn_info, m.chn): x, y = zip(*shape) m.plot(x, y, marker=none,color='k',linewidth = 0.5) info, shape in zip(m.twn_info, m.twn): x, y = zip(*shape) m.plot(x, y, marker=none,color='k',linewidth = 0.5) parallels = np.arange(-90.,91.,10.) m.drawparallels(parallels,labels=[1,0,0,1],linewidth=0.5,xoffset=1.2) meridians = np.arange(-180.,181.,10.) m.drawmeridians(meridians,labels=[1,0,0,1],linewidth=0.5,yoffset=1.2) u=dataset(r'd:\python\try\ncep\uwnd.2016.nc','r') v=dataset(r'd:\python\try\ncep\vwnd.2016.nc','r') hgt_data=dataset(r'd:\python\try\ncep\hgt.2016.nc','r') uwnd=u.variables['uwnd'][728][2][:] vwnd=v.variables['vwnd'][728][2][:] hgt=hgt_data.variables['hgt'][728][2][:] lat=u.variables['lat'][:] lon=u.variables['lon'][:] index1=np.logical_and(lon>=90,lon<=130);index2=np.logical_and(lat>=20,lat<=50) lons=lon[index1];lats=lat[index2] u1=uwnd[index2,:];u2=u1[:,index1] v1=vwnd[index2,:];v2=v1[:,index1] hgt1=hgt[index2,:];hgt2=hgt1[:,index1] nx,ny=np.meshgrid(lons,lats) x,y=m(nx,ny) q = m.quiver(x,y,u2,v2,scale=250,width=0.003) qk = plt.quiverkey(q, 0.85, -0.12, 20, '20 m/s', labelpos='n') rbf = scipy.interpolate.rbf(x, y, hgt2) zi = rbf(x, y) plt.contour(x,y,zi,color='k') plt.show() update:
lons = zoom(lons,3,order=3) lats = zoom(lats,3,order=3) x,y = np.meshgrid(lons,lats,copy=false) hgt2 = zoom(hgt2,3,order=3) cs = plt.contour(x,y,hgt2,levels=levels,colors='k',linewidths=0.7)
have @ examples contour() function on matplotlib site https://matplotlib.org/examples/pylab_examples/contour_demo.html
heres how generate x , y coordinates plot:
delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) x, y = np.meshgrid(x, y) what need increase resolution lons , lats fields use in meshgrid() function in own program.
higher resolution -> smoother lines
Comments
Post a Comment