1

I am trying to generate contour maps using irregular data after gridding the data in python. I am getting something like the image on left while I am trying to get a contour plot like the one on the right side without any white spaces in my plot (unplotted space ?)

Contour 1 Contour 2

I am initially creating a grid using the below code

def grid(x, y, z, resX=100, resY=100):
  xi = linspace(min(x), max(x), resX)
  yi = linspace(min(y), max(y), resY)
  Z = griddata(x, y, z, xi, yi, interp='linear')
  X, Y = meshgrid(xi, yi)
  return X, Y, Z
X, Y, Z = grid(x, y, z)
contour = plt.contourf(X,Y,Z)

Where x,y,z are columns from my csv file.

I tried using other methods like using matplotlib.pyplot.tricontourf but the plot looks similar to the one I am getting.

Rbf from scipy.interpolate.rbf gives a plot similar to the one on right side if I use a subset of my data but it doesn't work for large datasets.

5
  • Check griddata docs; and the Z values. I suspect the white spaces are nan values, for grid points outside the hull of the data. That is, where it would have to extrapolate. Commented Jul 4, 2017 at 22:43
  • @hpaulj im dropping the missing values if you mean that. TIA Commented Jul 4, 2017 at 22:49
  • Have you played with any of the contour keyword values? Commented Jul 4, 2017 at 23:53
  • @hpaulj I tried increasing the contour levels. I worked with plt.contourf before switching to plt.tricontourf as this does not require me to explicitly grid the data. The results are similar for contourf and tricontourf Commented Jul 6, 2017 at 8:57
  • Sorry that don't really understand what you are looking for. Will delete my answer. Commented Jul 6, 2017 at 13:38

1 Answer 1

1

You need to extrapolate in order to cover the empty spaces. Griddata interpolates within a convex hull of your data. In order to extrapolate the data you can use SciPy’s RBF (radial basis functions) interpolation. There are a few interpolation options with RBF (linear, cubic, Gaussian, ect.). Another option is to use sklearn’s “Gaussian process regression” to predict the values throughout your grid space. This option will require more work that SciPy’s built in RBF but it’s also more flexible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.