python - Python中离散点到x / y坐标网格网格的空间插值
问题描述
我对编程和尝试使用 Cartopy 创建整个夏威夷的碱度等值线图还是很陌生。我将需要根据 xy 网格插入名为 MODIFIED_TA 的点值,但无法弄清楚如何执行此操作。我正在使用的代码是:
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
import statistics
from scipy.interpolate import UnivariateSpline
import numpy as np
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import warnings
warnings.filterwarnings("ignore") # ignoring the warning prompts.
%matplotlib inline
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=-170))
landgreen = cfeature.NaturalEarthFeature('physical', 'land', '110m',
edgecolor='face', facecolor='green')
oceanaqua = cfeature.NaturalEarthFeature('physical', 'ocean', '110m',
edgecolor='face', facecolor='aqua')
ax.set_extent([-151.5, -162, 18, 24], ccrs.PlateCarree())
ax.set_title('TOTAL ALKALINITY')
ax.add_feature(landgreen)
ax.add_feature(cfeature.OCEAN, color = 'k')
ax.gridlines(draw_labels=True)
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.grid(linewidth=2, color='black', alpha=0.5, linestyle='--')
lons = all_data.LONGITUDE[:]
lats = all_data.LATITUDE[:]
alk = all_data.MODIFIED_TA[:]
x1,y1 = np.meshgrid(lons,lats)
z1,z2 = np.meshgrid(all_data.MODIFIED_TA,all_data.MODIFIED_TA)
plt.tricontourf(lons,lats,alk, transform=ccrs.PlateCarree(), cmap=cm.gist_rainbow)
plt.colorbar(shrink=0.5)
plt.title('$A_{T}$ VALUES', color = 'k', fontname='Times New Roman',size = 23)
plt.plot()
结果与我所希望的完全不同,我不知道如何插入这个值,以便它在 x/y 坐标网格上呈现为平滑渐变。任何帮助将不胜感激!
解决方案
如果无法查看您的数据,就很难确定。我试图创建一个MRE并且它有效。我会先看看这是否有效。
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.mpl.ticker as cticker
import numpy as np
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(central_longitude=-170))
ax.set_extent([-151.5, -162, 18, 24], ccrs.PlateCarree())
ax.add_feature(cfeature.OCEAN)
ax.gridlines(draw_labels=True)
lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.grid(linewidth=2, color='black', alpha=0.5, linestyle='--')
lons = np.random.random(80) * 7 - 160
lats = np.random.random(80) * 4 + 19
alk = np.cos(lons * 10 * np.pi / 180) * np.sin(lats * 20 / 180)
plt.plot(lons, lats, 'k.', transform = ccrs.PlateCarree())
plt.tricontourf(lons,lats,alk, transform=ccrs.PlateCarree(), alpha = 0.5)
plt.colorbar(shrink=0.5)
plt.title('$A_{T}$ VALUES', color = 'k', fontname='Times New Roman',size = 23)
如果它确实有效,那么我要看的内容包括:
all_data.LONGITUDE
,all_data.LATITUDE
,的尺寸是all_data.MOTIFIED_TA
多少?- 是否存在重复值?
- 当您在投影之外绘制它时它是否有效?
如果我的示例不起作用,则表明您的安装存在某些问题,在这种情况下,如果可以,请对其进行更新。如果问题仍然存在,则可能存在cartopy
需要报告的错误或与其他软件包的冲突。
抱歉,我无法提供更多帮助。
推荐阅读
- sql - 从 MSSQL 表中返回日期小于或等于当前日期的唯一记录
- node.js - Stripe + TypeScript:如何扩展条带节点的@types/stripe 定义?
- sql - 如何使用在 INSERT 语句中返回表的函数?
- contour - 如何使用网格文件中的轮廓过滤器在 Paraview 中提取等值面?
- hyperledger-fabric - Hyperledger Explorer:如何防止参与者访问交易历史
- javascript - jquery中.add()的等效javascript函数是什么?
- angular - Angular 6 库组件和 SCSS
- vue.js - VueJS 中的条件链接行为
- c# - LINQ - 组到模型
- html - 折叠时增加引导 4 卡的高度和宽度?