第八星系人气爱 发表于 2024-2-29 17:34:07

Python绘制相关系数空间分布图

本帖最后由 第八星系人气爱 于 2024-2-29 17:48 编辑

作者:第八星系—GuGu邮箱:gu2001yi@163.com
1.导入库

import numpy as np
import xarray as xr
import cmaps
import pandas as pd
from eofs.standard import Eof
import matplotlib.pyplot as plt
from scipy import signal
from sklearn import preprocessing
from scipy.stats import pearsonr
#from scipy.stats import linregress
import datetime as dt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
from cartopy.util import add_cyclic_point
import matplotlib.patches as patches2.读取数据
path = 'D:\\NCEP\\NCEPdata\\air.mon.mean.nc'
f_t=xr.open_dataset(path)
#挑选时间·位势高度·经纬度
yy= f_t['air'].loc)].loc['1954-01-01':'2003-09-01'].loc[:,500:200,90:0, 0:360]
#作夏季平均
yy1=np.array(yy).reshape(50,3,5,37,144).mean(1)
#纬向平均
xx2=np.array(yy1).mean(3)
xx3=xx2[:,:,:,np.newaxis]
#计算扰动温度
tt=yy1-xx3
apo1=np.array(yy1).mean(1)
#计算指数
apo0,apo= np.zeros(50),np.zeros(50)
for i in range(0,50):
      apo0 = np.mean(apo1) - np.mean(apo1)

path = "D:\\SSTdata\\sst.mnmean.nc"
f_t = xr.open_dataset(path)
tt1=np.array(f_t.sst.loc)].loc['1954-05-01':'2003-09-01']).reshape(50,3,89,180)
tt1=0
tt1=np.array(tt1).mean(1)#目标区域海温
lat = f_t.lat
lon = f_t.lon

r,p = np.zeros((89,180)),np.zeros((89,180))
for i in range(len(lat)):
    for j in range(len(lon)):
      r, p, = pearsonr(apo0,tt1[:,i,j])3.绘图
fig = plt.figure(figsize=(10,10))
proj = ccrs.PlateCarree(central_longitude=180)
leftlon, rightlon, lowerlat, upperlat = (120,240,20,60)
img_extent =

ax = fig.add_axes(,projection = proj)

ax.set_extent(img_extent, crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE)
#ax.add_feature(cfeature.LAND,color='whitesmoke')
#ax.add_feature(cfeature.OCEAN.with_scale('50m'))
#ax.add_feature(cfeature.LAKES.with_scale('50m'))
ax.set_xticks(np.arange(leftlon,rightlon+20,20), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(lowerlat,upperlat+10,10), crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_title('corr:APOI-sst',loc='left',fontsize =15)
c1 = ax.contourf(lon,lat, r, zorder=0,levels =np.arange(-1,1.1,0.1) , extend = 'both', transform=ccrs.PlateCarree(), cmap=plt.cm.bwr)
c1b = ax.contourf(lon,lat, p,levels=, zorder=1,hatches=['..', None],colors="none", transform=ccrs.PlateCarree())#显著性检验打点

position=fig.add_axes()
fig.colorbar(c1,cax=position,orientation='horizontal',format='%.1f',)
plt.show()

示意图


4.完整代码
import numpy as np
import xarray as xr
import cmaps
import pandas as pd
from eofs.standard import Eof
import matplotlib.pyplot as plt
from scipy import signal
from sklearn import preprocessing
from scipy.stats import pearsonr
#from scipy.stats import linregress
import datetime as dt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.ticker as cticker
from cartopy.util import add_cyclic_point
import matplotlib.patches as patches

path = 'D:\\NCEP\\NCEPdata\\air.mon.mean.nc'
f_t=xr.open_dataset(path)
#挑选时间·位势高度·经纬度
yy= f_t['air'].loc)].loc['1954-01-01':'2003-09-01'].loc[:,500:200,90:0, 0:360]
#作夏季平均
yy1=np.array(yy).reshape(50,3,5,37,144).mean(1)
#纬向平均
xx2=np.array(yy1).mean(3)
xx3=xx2[:,:,:,np.newaxis]
#计算扰动温度
tt=yy1-xx3
apo1=np.array(yy1).mean(1)
#计算指数
apo0,apo= np.zeros(50),np.zeros(50)
for i in range(0,50):
      apo0 = np.mean(apo1) - np.mean(apo1)



path = "D:\\SSTdata\\sst.mnmean.nc"
f_t = xr.open_dataset(path)
tt1=np.array(f_t.sst.loc)].loc['1954-05-01':'2003-09-01']).reshape(50,3,89,180)
tt1=0
tt1=np.array(tt1).mean(1)#目标区域海温
lat = f_t.lat
lon = f_t.lon

r,p = np.zeros((89,180)),np.zeros((89,180))
for i in range(len(lat)):
    for j in range(len(lon)):
      r, p, = pearsonr(apo0,tt1[:,i,j])

#绘图
fig = plt.figure(figsize=(10,10))
proj = ccrs.PlateCarree(central_longitude=180)
leftlon, rightlon, lowerlat, upperlat = (120,240,20,60)
img_extent =

ax = fig.add_axes(,projection = proj)

ax.set_extent(img_extent, crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE)
#ax.add_feature(cfeature.LAND,color='whitesmoke')
#ax.add_feature(cfeature.OCEAN.with_scale('50m'))
#ax.add_feature(cfeature.LAKES.with_scale('50m'))
ax.set_xticks(np.arange(leftlon,rightlon+20,20), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(lowerlat,upperlat+10,10), crs=ccrs.PlateCarree())
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_title('corr:APOI-sst',loc='left',fontsize =15)
c1 = ax.contourf(lon,lat, r, zorder=0,levels =np.arange(-1,1.1,0.1) , extend = 'both', transform=ccrs.PlateCarree(), cmap=plt.cm.bwr)
c1b = ax.contourf(lon,lat, p,levels=, zorder=1,hatches=['..', None],colors="none", transform=ccrs.PlateCarree())#显著性检验打点

position=fig.add_axes()
fig.colorbar(c1,cax=position,orientation='horizontal',format='%.1f',)
plt.show()
微信搜索“第八星系人造大气理论爱好者”公众号,关注获取文章数据

第八星系人气爱 发表于 2024-2-29 17:50:01

关注~

FrankJScott 发表于 2024-8-28 23:55:46

Recommended ASIAN2BET Info

For the guy inquiring about rtp live gem188, rtp slot saat ini, fortuneslot88 live, rtp live slot pragmatic tertinggi hari ini, rtp live bro138, rtp slot live hari ini, rtp 138 live, rtp slot pg soft hari ini, rtp live 2022, rtp live dibet4d,I highly suggest this excellent RTP ASIAN2BET advice or rtp jam gacor pragmatic hari ini, live gacor, rtp slot hari ini live, rtp pragmatic play slot hari ini, rtp live mlm ini, indonesia gacor, rtp pedro4d, slot gacor bri online 24 jam, mpo333bet live, rtp zeus hari ini, as well as this breaking news on ASIAN2BET url alongside all rtp live sultan33, rtp pjslot168, rtp pola jam gacor, spinhoki88 rtp live, rtp tergacor hari ini, rtp live slot777, jam slot pragmatic gacor, rtp mega303, rtp slot global hari ini, rtp slot pragmatic hari, not to mention this do you agree for ASIAN2BET tips which is also great. Also, have a look at this updated ASIAN2BET details and don't forget rtp live metro4d, gates of olympus indonesia, rtp pragmatic live hari ini, rtp tektok4d live, gacor77 rtp live, jam slot gacor higgs domino, vipslot77 live, rtp live slot gacor hari ini, live pragmatic slot, rtp live habanero88, not to mention this source for ASIAN2BET info with rtp hokicuan78, rtp live alexistogel, rtp live game slot, rtp live hari ini pragmatic, rtp live judi, info rtp live slot, rtp live slot mania, rtp live max77, rtp dan pola slot pragmatic hari ini, rtp mlm ini,for good measure. Check more @ Best RTP ASIAN2BET Tips ab878d0

FrankJScott 发表于 2024-9-3 10:30:09

Cool CUANSLOT Guide

To the lady talking about 4d singapore slot, idn 4d slot, bandar togel online, toto malaysia online, toto judi, 4d toto, master wap, 4d singapore login, 2d toto, judi slot4d,I highly recommend this high rated CUANSLOT site or agen slot4d, judi slot4d, bandar togel terbesar dan terpercaya di indonesia, slot 4d singapore, bandar togel bri 24 jam, judi 4d online, agen slot 2d, 5505 4d, toto judi slot, toto 4d toto, alongside all this updated CUANSLOT forum and don't forget tot9 4d, slot 4d singapore, agen macau, judi toto slot, bandar judi toto, toto game, cara main 4d, 4d toto 4d, 4d judi, sdy slot4d, not to mention this more tips here about CUANSLOT forum which is also great. Also, have a look at this had me going for CUANSLOT88 details on top of website 4d, judi hk online, dewatogel singapore, cara menang toto 4d, cara main 4d singapore, toto login, singapore 4d slot, toto 4d toto, cara main 4d, bandar online deposit pulsa, as well as this i thought about this on CUANSLOT88 link with idn 4d slot, 4d 4d toto, bandar judi togel online, bandar judi togel, judi online 4d, 4d singapore login, bandar slot 4d, judi hongkong online, toto malaysia online, toto 4d,for good measure. Check more @ Updated UG ZEUS Guide cdecb1e

FrankJScott 发表于 2024-9-9 23:01:59

Useful Google Indexing Guide

For the people talking about my website is not on google, google search bots, google deindex, google site index check, google search engine description, google does not find my website, site search url, make google crawl your website, get website indexed by google, best seo links,I highly recommend this great google indexing link or submit to google index, submit site for indexing, force google reindex, seo your website, index my website on google, view page as googlebot, submit your url, search console website, request indexing google, recrawl website, as well as this funny post for google indexing forum on top of index now seo, submit link to google, index my website google search engine, indexer tool, noindex html tag, website not showing, google website indexing time, index of site, crawling indexing and ranking in seo, website indexing tool, and don't forget this cool google indexing url which is also great. Also, have a look at this discover more here about google indexing forum on top of google seo site, meta tag robots noindex, pages not indexed by google, check if website is on google, submit domain to search engines, noindex seo, index my page on google, check if site is indexable, submit your website to google, check if googlebot can access site, and don't forget this updated blog post on google indexing site with search engine backlinks, google not indexing my pages, check website google indexing, google not showing my website, google not indexing, wordpress instant indexing, add my website to google search engine, free website indexing, url search console, google find links to site,for good measure. Check more @ Top 7RAJATOGEL Site e7069c2
页: [1]
查看完整版本: Python绘制相关系数空间分布图