python讀取NC文件畫風速等值線圖

關於用basemap畫圖,可以去看我的另一篇博客,那篇很全面,這篇主要學習怎麼讀取nc等文件


有些部分沒有調好,比如等值線的間隔、顏色等,不過會繼續學習的。現在先做一下筆記。

#coding=utf-8
__author__ = 'kong'

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap, cm
import netCDF4 as nc


filename='C:\\Users\\kong\\PycharmProjects\\replacencl\\meow'
data=nc.Dataset(filename)
for i in data.variables.keys():
  print(i)
lat= data.variables['XLAT_U'][:].squeeze()
lon= data.variables['XLONG_U'][:].squeeze()
u=data.variables['U'][:].squeeze()
idate=data.variables['Times']


m=Basemap(resolution='l',area_thresh=10000,projection='cyl',llcrnrlon=50,urcrnrlon=150,llcrnrlat=0,urcrnrlat=70)

fig1 = plt.figure()
ax = fig1.add_axes([0.1,0.1,0.8,0.8])
#clevls_hgt=[-80,-60,-40,-20,0,20,40,60,80]
x, y = m(lon, lat)
#parallels = np.arange(-90.,90,30.)
#meridians = np.arange(0.,360.,60.)
CS2 = m.contour(x,y,u[0,:,:],origin='lower',cmap=plt.get_cmap('Blues'),extend='both')
CS2.clabel()
m.drawcoastlines(linewidth=0.2)
plt.title('U',size=20)
#plt.xlim(50,150)
#plt.ylim(0,70)

plt.show()

python讀取NC文件畫風速等值線圖_第1张图片

真是丑到一個境界ORZ




改了,好看多了

filename='C:\\Users\\kong\\PycharmProjects\\replacencl\\meow'
data=nc.Dataset(filename)
for i in data.variables.keys():
  print(i)
lat= data.variables['XLAT_U'][:].squeeze()
lon= data.variables['XLONG_U'][:].squeeze()
u=data.variables['U'][:].squeeze()
idate=data.variables['Times']


m=Basemap(resolution='l',area_thresh=10000,projection='cyl',llcrnrlon=50,urcrnrlon=150,llcrnrlat=0,urcrnrlat=70)

fig1 = plt.figure()
ax = fig1.add_axes([0.1,0.1,0.8,0.8])
#clevls_hgt=[-80,-60,-40,-20,0,20,40,60,80]
x, y = m(lon, lat)
m.drawparallels(np.arange(0,70,10.),labels=[1,1,0,0],fontsize=15)
m.drawmeridians(np.arange(50,150,20),labels=[0,0,0,1],fontsize=15)
#curve=m.contour(x,y,u[0,:,:],colors='k')
CS2=m.contourf(x,y,u[0,:,:])
m.colorbar(CS2)
m.drawcoastlines(linewidth=0.2)
plt.title('U',size=20)


plt.show()

python讀取NC文件畫風速等值線圖_第2张图片

你可能感兴趣的:(Python黑科技,ATMOS)