我想知道是否有人有一个示例来显示 xarray 和 numpy 包之间的性能(内存和速度)比较。谢谢
我正在尝试在等高线图上添加阴影线(如点、散列等)。这种阴影线可以代表唯一具有统计显着性的轮廓,或者具有某些标准的轮廓。就像下面关于自然文章的图片(第二个和第三个图)http://www.nature.com/articles/srep16853/figures/3。
\n\n以下代码显示了来自 NOAA 数据的降水图,可在以下位置下载。
\n\nimport numpy as np\nimport sys \nimport netCDF4 as nc\nimport matplotlib.pyplot as plt\nimport matplotlib.mlab as m \nimport mpl_toolkits.basemap as bm\nimport os\nsys.path.insert(0, \'../\');import py4met as sm;reload(sm)\n\n#- Reading data for a timeslice, latitude, and longitude:\ndiri_output="./"\ndiri="./"\ntmp_file = nc.Dataset(diri+"precip.mon.mean.nc","r")\nprint(tmp_file.variables)\np_pre = tmp_file.variables[\'precip\']\nlat = tmp_file.variables[\'lat\'][:]\nlon = tmp_file.variables[\'lon\'][:]\ntime = tmp_file.variables[\'time\']\ntmp_file.close\n\n\nlat1=np.min(lat)\nlat2=np.max(lat)\nlon1=np.min(lon)\nlon2=np.max(lon)\n\n[lonall, latall] = np.meshgrid(lon[:], lat[:])\nplt.figure(num=None, figsize=(8+4, 6+4), dpi=80, facecolor=\'w\', edgecolor=\'k\') \nmapproj = bm.Basemap(projection=\'cyl\',llcrnrlat=lat1, llcrnrlon=lon1,urcrnrlat=lat2, urcrnrlon=lon2,resolution=\'l\')\nmapproj.drawcoastlines()\nmapproj.drawmapboundary(fill_color=\'white\')\nmapproj.drawcountries()\nx, y = mapproj(lonall, latall)\nplt.contourf(x,y,p_pre[240,:,:],cmap=plt.cm.GnBu)\nplt.colorbar(orientation=\'horizontal\',pad=0.05,shrink=0.6)\nplt.title("title")\nxx,yy=np.where(p_pre[240,:,:] >= 20)\nsig=np.copy(p_pre[0,:,:])\nsig[:,:]=1\nsig[xx,yy]=0\n#plt.contourf(x,y,sig,hatches=[\'.\'])\nplt.show() \n
Run Code Online (Sandbox Code Playgroud)\n\n我想孵化所有20毫米以上的轮廓,所以我使用了上面的命令
\n\n\n\n\n …plt.contourf(x,y,sig,hatches=[\'.\'])
\n
我在地球科学应用中广泛使用 Python(Canopy)。因为我的应用程序是内存消耗,我试图找到方法来擦除我的程序中不再需要的变量,我尝试使用 del 命令来擦除变量内存,但我发现 Canopy 使用的空间仍然是相同的。关于如何从内存中完全擦除变量的任何想法。谢谢
我正在尝试使用matplotlib fill_between函数,但出现以下错误“ TypeError:输入类型不支持ufunc'isfinite',并且根据转换规则” safe无法将输入安全地强制转换为任何受支持的类型””
我在x轴中使用了熊猫的datetime,并认为这会引发此类问题。我尚无法找到解决方案。
这是代码
#%%
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Open file
f = open('rmm.74toRealtime.txt', 'r')
# Read and ignore header lines
header1 = f.readline()
header2 = f.readline()
n=15461-2
year=np.zeros(n)
month=np.zeros(n)
day=np.zeros(n)
rmm1=np.zeros(n)
rmm2=np.zeros(n)
phase=np.zeros(n)
ampl=np.zeros(n)
a=np.zeros(n)
b=np.zeros(n)
i=0
# Loop over lines and extract variables of interest
for line in f:
line = line.strip()
columns = line.split()
year[i] = columns[0]
month[i]=columns[1]
day[i]=columns[2]
rmm1[i]=columns[3]
rmm2[i]=columns[4]
phase[i]=columns[5]
ampl[i]=columns[6]
print([float(year[i]),float(month[i]),float(day[i]),float(rmm1[i]),float(rmm2[i]),float(phase[i]),float(ampl[i])])
a[i]=str(int(year[i]))+str(int(month[i])).zfill(2) +str(int(day[i])).zfill(2) …
Run Code Online (Sandbox Code Playgroud) python ×4
matplotlib ×2
python-2.7 ×2
python-3.x ×2
anova ×1
arrays ×1
canopy ×1
contour ×1
ipython ×1
numpy ×1
statistics ×1