Program hangs when using “matplotlib.mlab.griddata”

╄→尐↘猪︶ㄣ 提交于 2019-12-01 08:52:12

It's failing because you're trying to interpolate over a very strange region.

Look at your input coordinates, your data is all in a line, but you're trying to interpolate in 2D. Your yi coordinates are all the same!

If you want 1D interpolation, then just use one of the many 1D interpolation routines... (numpy.interp if you just want linear interpolation or scipy.interp1d if you need splines of some sort. There are several other options as well...).

What does the full dataset look like?

griddata uses delauney triangulation by default. Anytime you wind up making very thin, near-zero-area triangles between your input points, this algorithm will have problems.

If you really want to interpolate in 2D over a region with an area of zero (See the problems here!!) try another (preferably 1D) interpolation algorithm. If you want help let me know.

If you really do want a "pseudo-2D" interpolation, scipy.interpolate.Rbf using a linear distance function would be one choice. Just be aware that the (2D) results may not be what you expect as you have absolutely no variation in the y-direction...

Alternately you could just tile the 1D interpolation results in the y-direction if you want everything to be the same in the y-direction.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!