Everyone,
I am currently having some difficulty with the interpolation produced by griddata in matplotlib. I have a data set that contains 3 values per a data point. I am attempting to plot this data in a contour. The problem I am having is that the the built in delauny interpolation breaks on some data sets. So, I have tried to move over to the natgrid interpolatoin. This works for some data. However, other data sets it produces some null values in the output of griddata. I should also mention that these null values occur in an area where most values are the same (0 in this case).
Are there any suggestions as to what could cause this?
Edit: Here are some more details.
The source data is rather large and cannot be pasted in here. So, I used a pastebin to hold it. I hope this is allowed. That is available here: http://pastebin.com/C7Nvvcaw. This is formatted like x, y, z. So the first column is the x value and so on. This is the result for printing every item in the xyz list and piping it into a file.
The same applies for the post interpolation data. So, I have used a pastebin as well. Here it is: http://pastebin.com/ZB6S2qFk. Each [] corresponds with a particular y value. The y values are not included because they are in the separate lists. Though, they just range from 0-50 for the Y axis and 0-100 for the X axis. This is the output of printing every item in the zi list from my code and piping it into a file.
Now for the code, I have not attached all of the code because a large part of it is out of the scope of this question. So, I will post the relevant components. The initial data is in a list of lists providing the ability to navigate the data in 3 dimensions. I suppose this is similar to a 3 dimensional array, though it is not and just a list of lists. The source data's list is called xyz.
#Function to get individual column of data
def column(matrix, i):
return [row[i] for row in matrix]
#Getting Max and Mins
xmin = float(min(column(xyz, 0)))
xmax = float(max(column(xyz, 0)))
ymin = float(min(column(xyz, 1)))
ymax = float(max(column(xyz, 1)))
#Resolution for interpolation (x and y list lengths)
resx = 100
resy = 50
xi = np.linspace(xmin, xmax, resx)
yi = np.linspace(ymin, ymax, resy)
x = np.array(column(xyz, 0))
y = np.array(column(xyz, 1))
z = np.array(column(xyz, 2))
zi = griddata(x, y, z, xi, yi, interp='nn')
EDIT: I found a solution. The 0 values are breaking the interpolation. I was able to catch them and change them all to 0.1 and the interpolation no longer produces the null values. this is acceptable in my case because 0 and 0.1 fall under the same contour color. For other users if you need to retain absolute accuracy of the data, I would suggest transforming all the values by +1, interpolating, then transforming the interpolated values -1. This will retain the accuracy without breaking the interpolation method.
Thanks for any help,
Daniel