Python怎么實(shí)現(xiàn)全球氣溫圖

這篇文章主要講解了“Python怎么實(shí)現(xiàn)全球氣溫圖”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Python怎么實(shí)現(xiàn)全球氣溫圖”吧!

創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括陜州網(wǎng)站建設(shè)、陜州網(wǎng)站制作、陜州網(wǎng)頁(yè)制作以及陜州網(wǎng)絡(luò)營(yíng)銷(xiāo)策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,陜州網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到陜州省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

2012年全球平均空氣溫度圖:

注:本文僅以basemap為例,cartopy請(qǐng)讀者參照往期推文自行修改。
import datetime as dt  # Python standard library datetime  moduleimport numpy as npfrom netCDF4 import Dataset  # http://code.google.com/p/netcdf4-python/import matplotlib.pyplot as pltfrom mpl_toolkits.basemap import Basemap, addcyclic, shiftgridnc_f = 'F:/Rpython/lp28/data/air.sig995.2012.nc'  # Your filenamenc_fid = Dataset(nc_f, 'r')  # Dataset is the class behavior to open the file  # and create an instance of the ncCDF4 class# Extract data from NetCDF filelats = nc_fid.variables['lat'][:]  # extract/copy the datalons = nc_fid.variables['lon'][:]time = nc_fid.variables['time'][:]air = nc_fid.variables['air'][:]  # shape is time, lat, lon as shown abovetime_idx = 237  # some random day in 2012# Python and the renalaysis are slightly off in time so this fixes that problemoffset = dt.timedelta(hours=48)# List of all times in the file as datetime objectsdt_time = [dt.date(1, 1, 1) + dt.timedelta(hours=t) - offset\           for t in time]cur_time = dt_time[time_idx]# Plot of global temperature on our random day#fig = plt.figure()#fig.subplots_adjust(left=0., right=1., bottom=0., top=0.9)fig=plt.figure(figsize=(16,9))ax=fig.add_subplot(111)# Setup the map. See http://matplotlib.org/basemap/users/mapsetup.html# for other projections.m=Basemap(llcrnrlat=-90,urcrnrlat=90,llcrnrlon=-180,urcrnrlon=180,resolution='c')m.drawparallels(np.arange(-90, 90 + 1, 30), labels = [1, 0, 0, 0],fontsize=14,linewidth='0.2',color='black')m.drawmeridians(np.arange(-180, 180 + 1, 60), labels = [0, 0, 0, 1],fontsize=14,linewidth='0.2',color='black')m.drawcoastlines()m.drawmapboundary()air2=air[time_idx,:,:]# 將0~360轉(zhuǎn)化為-180~180# Make the plot continuousair_cyclic, lons_cyclic = addcyclic(air2, lons)# Shift the grid so lons go from -180 to 180 instead of 0 to 360.air_cyclic, lons_cyclic = shiftgrid(180., air_cyclic, lons_cyclic, start=False) #False True# Create 2D lat/lon arrays for Basemaplon2d, lat2d = np.meshgrid(lons_cyclic, lats)# Transforms lat/lon into plotting coordinates for projectionx, y = m(lon2d, lat2d)# 查看數(shù)組緯度dimen = np.array(x).shapeprint(dimen)dimen1 = np.array(y).shapeprint(dimen1)dimen2 = np.array(air_cyclic).shapeprint(dimen2)# Plot of air temperature with 11 contour intervalsclevs = np.arange(200,320,10)cs = m.contourf(x,y,air_cyclic,clevs,cmap='gist_rainbow',extend='both')cbar=plt.colorbar(cs,shrink=0.75,orientation='vertical',extend='both',pad=0.025,aspect=20) #orientation='horizontal'#cbar = plt.colorbar(cs, orientation='horizontal', shrink=0.5)cbar.set_label("%s (%s)" % (nc_fid.variables['air'].var_desc,nc_fid.variables['air'].units))plt.title("%s on %s" % (nc_fid.variables['air'].var_desc, cur_time))plt.savefig('F:/Rpython/lp28/plot33.png',dpi=800)plt.show()

Python怎么實(shí)現(xiàn)全球氣溫圖


2012年澳大利亞達(dá)爾文市的溫度曲線:

darwin = {'name': 'Darwin, Australia', 'lat': -12.45, 'lon': 130.83}# Find the nearest latitude and longitude for Darwinlat_idx = np.abs(lats - darwin['lat']).argmin()lon_idx = np.abs(lons - darwin['lon']).argmin()# Simple example: temperature profile for the entire year at Darwin.# Open a new NetCDF file to write the data to. For format, you can choose from# 'NETCDF3_CLASSIC', 'NETCDF3_64BIT', 'NETCDF4_CLASSIC', and 'NETCDF4'w_nc_fid = Dataset('F:/Rpython/lp28/data/darwin_2012.nc', 'w', format='NETCDF4')w_nc_fid.description = "NCEP/NCAR Reanalysis %s from its value at %s. %s" %\                      (nc_fid.variables['air'].var_desc.lower(),darwin['name'], nc_fid.description)# Using our previous dimension info, we can create the new time dimension# Even though we know the size, we are going to set the size to unknownw_nc_fid.createDimension('time', None)w_nc_dim = w_nc_fid.createVariable('time', nc_fid.variables['time'].dtype,('time',))# You can do this step yourself but someone else did the work for us.for ncattr in nc_fid.variables['time'].ncattrs():    w_nc_dim.setncattr(ncattr, nc_fid.variables['time'].getncattr(ncattr))# Assign the dimension data to the new NetCDF file.w_nc_fid.variables['time'][:] = timew_nc_var = w_nc_fid.createVariable('air', 'f8', ('time'))w_nc_var.setncatts({'long_name': u"mean Daily Air temperature",\                    'units': u"degK", 'level_desc': u'Surface',\                    'var_desc': u"Air temperature",\                    'statistic': u'Mean\nM'})w_nc_fid.variables['air'][:] = air[time_idx, lat_idx, lon_idx]w_nc_fid.close()  # close the new file# A plot of the temperature profile for Darwin in 2012fig = plt.figure()plt.plot(dt_time, air[:, lat_idx, lon_idx], c='r')plt.plot(dt_time[time_idx], air[time_idx, lat_idx, lon_idx], c='b', marker='o')plt.text(dt_time[time_idx], air[time_idx, lat_idx, lon_idx], cur_time,ha='right')fig.autofmt_xdate()plt.ylabel("%s (%s)" % (nc_fid.variables['air'].var_desc,nc_fid.variables['air'].units))plt.xlabel("Time")plt.title("%s from\n%s for %s" % (nc_fid.variables['air'].var_desc,darwin['name'], cur_time.year))plt.savefig('F:/Rpython/lp28/plot33.2.png',dpi=800)plt.show()

Python怎么實(shí)現(xiàn)全球氣溫圖

感謝各位的閱讀,以上就是“Python怎么實(shí)現(xiàn)全球氣溫圖”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)Python怎么實(shí)現(xiàn)全球氣溫圖這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)站欄目:Python怎么實(shí)現(xiàn)全球氣溫圖
鏈接分享:http://bm7419.com/article32/igiisc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、外貿(mào)建站、網(wǎng)站排名、品牌網(wǎng)站設(shè)計(jì)、Google、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司