Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use griddata from scipy.interpolate

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()
like image 651
questionhang Avatar asked Aug 11 '13 15:08

questionhang


People also ask

What does Scipy interpolate Griddata do?

interpolate. griddata() method is used to interpolate on a 2-Dimension grid.

What does Scipy interpolate interp1d return?

This class returns a function whose call method uses interpolation to find the value of new points. A 1-D array of monotonically increasing real values. A N-D array of real values.

How do you use spline in Python?

To represent spline interpolation smoothing coefficients can be taken parametrically or directly. The 'splrep' function helps us to define the curve with direct method. It provides t, c, k tuple containing the vector of knots, the B-spline coefficients, and the degree of the spline.


1 Answers

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.

like image 141
cossatot Avatar answered Sep 28 '22 09:09

cossatot