如何使用scipy.interpolate中的griddata [英] How to use griddata from scipy.interpolate

查看:2334
本文介绍了如何使用scipy.interpolate中的griddata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含300万行的三列(x像素,y像素,z值)数据.数据来自图像,并且z值重复.现在,我需要绘制表面图. 此图片是一个很好的例子.但是现在输出图像为空.有人可以检查代码吗?

I have a three-column (x-pixel, y-pixel, z-value) data with one million lines. The data is from an image and there are duplicated z-values. Now I need to make a surface plot. This image is a perfect example. But now the output image is null. Could someone check the code please?

import numpy as np
from enthought.mayavi import mlab
from scipy.interpolate import griddata
x,y,z = np.loadtxt('test.csv',delimiter=',',usecols=(0,1,2),unpack=True) 
xi,yi = np.mgrid[0:3000:3000j, 0:3000:3000j]
zi = griddata((x, y), z, (xi, yi),method='linear')
mlab.surf(xi,yi,zi)
mlab.show()

推荐答案

我无法在没有数据的情况下检查代码,但我怀疑问题是您使用默认的fill_value=nan作为griddata参数,因此,如果网格点的延伸超出(x,y)点的空间,则网格中会存在NaN,而mlab可能无法处理(Namtlotlib并不容易).尝试设置fill_value=0或其他合适的实数.

I can't check the code without having the data, but I suspect that the problem is that you are using the default fill_value=nan as a griddata argument, so if you have gridded points that extend beyond the space of the (x,y) points, there are NaNs in the grid, which mlab may not be able to handle (matplotlib doesn't easily). Try setting fill_value=0 or another suitable real number.

这篇关于如何使用scipy.interpolate中的griddata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆