gpt4 book ai didi

python - 带空白区域的 Matplotlib 等高线

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:29 28 4
gpt4 key购买 nike

我有一组数据,其中包含 x 和 y 坐标以及每个坐标的计算值。网格是不规则的,所以现在我一直在创建一个散点图并将值分成多个箱子,以显示为下面链接中 img 上的等高线。 http://i.stack.imgur.com/m7XHm.png

我想通过使用 meshgrid 使用 matplotlib 中的 imshow/contour 功能改进此方法,然后对计算值进行插值。我可以让它正常工作,但我最终遇到了一个问题,它丢失了没有数据的图像区域(现实生活中的空隙)并将它们连接起来,如下面链接中的图像所示,以获得相同的数据。 http://i.stack.imgur.com/ZCRog.png

我试图找到最好的方法来做到这一点,但我没有找到任何帮助。有人有什么建议吗?

我想我需要在 meshgrid 阶段修改方法,但我不确定这一点。下面是我的代码的值(value)

    x=nodalData[:,1] #array of x values from input file
y=nodalData[:,2] #array of y values from input file

#define the linear grid
xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100)
xi, yi = np.meshgrid(xi, yi)

z=Rres #array calculated elsewhere corresponding to x,y pair

#interpolate
zi = scipy.interpolate.griddata((x, y), z, (xi, yi), method='cubic')
#plot
plt.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower', extent=[x.min(), x.max(), y.min(), y.max()])

最佳答案

这是一个奇怪的问题,因为插值点是为数据不足的区域找到合理的估计值。我建议要么接受新图具有内插值,那么如果“无数据”区域不再存在就可以了。或者,您可以在进行插值后将 data voids 放回原处,例如使用您的第一个绘图作为掩码。

关于python - 带空白区域的 Matplotlib 等高线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10285598/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com