我从一个更大的数据集创建了一个表,它给了我想要绘制的y,x和z值。我创建了一个网格,然后插值,但我不认为函数沿着行的插值正确,因为我可以看到数据在图中纬度78-80附近的分裂点(见图),这使我认为沿行的插值没有正确完成。有没有人知道如何平滑这些数据?
aou_df = df_1994.pivot_table(index='CTDPRS', columns = 'LATITUDE', values='AOU')
aou_df = aou_df.interpolate(method='linear', limit_area='inside', axis =0 )
##Plotting AOU 1994
y = ([ 4.2, 4.7, 4.8, 4.9, 5.4, 9.1, 9.6, 9.7,
10.0, 10.1,
...
3568.2, 3608.6, 3818.6, 3824.9, 3866.7, 3979.1, 4013.4, 4133.1,
4159.3, 4287.3],
x= ([72.13, 73.0, 73.49, 73.98, 74.5, 75.0, 75.45, 75.75, 75.94,
76.62, 77.33, 77.78, 78.14, 78.15, 78.98, 79.98, 80.15, 80.16,
80.33, 80.71, 81.24, 81.58, 82.47, 83.17, 84.06, 84.85, 85.89,
87.16, 88.06, 88.79, 88.86, 88.95, 89.02, 90.0],
z = [[-12.29372749, nan, nan, ..., nan,
nan, nan],
[ nan, nan, -43.41465869, ..., nan,
nan, nan],
[ nan, -54.49999783, nan, ..., nan,
nan, nan],
...,
[ nan, nan, nan, ..., nan,
nan, nan],
[ nan, nan, nan, ..., nan,
55.87256821, nan],
[ nan, nan, nan, ..., 55.39665852,
nan, 55.05005376]])
xi, yi = np.meshgrid(x,y,indexing='ij')
#from matplotlib.colors import LogNorm
plt.figure(figsize=(25,10))
levels = np.linspace(-135,135)
#cbar = plt.colorbar(ticks=(-85,-65,-45,-25,-5,15,35,55,75,95, 115,135))
plt.contourf(xi,yi,z, cmap = 'jet', levels=levels,vmin=-135, vmax=135)
plt.gca().invert_yaxis()
plt.gca().invert_xaxis()
cbar = plt.colorbar(ticks=(-135,-110,-85,-60,-35,0,35,60,85,110,135), extend= 'both')
cbar.set_label('AOU', fontsize=18)
cbar.ax.tick_params(labelsize=18)
plt.xlabel('LAT',fontsize=18)
plt.ylabel('Pressure (dbar)' ,fontsize=18)
plt.ylim(bottom = 1000)
plt.xticks(fontsize=18)
plt.yticks(fontsize=18)
plt.plot(x,range(len(x)),'gD', clip_on=False, markersize=10)
#plt.xlim(left = 80)
1条答案
按热度按时间efzxgjgh1#
好的,数值在一个表格里。。对不起...我更新了代码。。试着跑。。
试试这个...你可以将
method='Linear'
和method='Cubic'
传递给griddata
编辑:这是Joao的代码使用method='nearest'
得到的结果
这是“线性”结果: