2020腾讯云双十一活动，全年最低！！！（领取3500元代金券），
地址：https://cloud.tencent.com/act/cps/redirect?redirect=1074
【阿里云】双十一活动，全年抄底价，限时3天！(老用户也有)，
入口地址：https://www.aliyun.com/1111/home
Is anybody of you aware of a higher order interpolation method (CatmullRom splines, cubic interpolation, etc.) for 2D contouring in Python?
Skimage, Matplotlib, and OpenCV provide the functions measure.find_contours(), contours() and findContours() respectively, but all are based on linear interpolation (also known as marching squares), I'm looking into something with higher accuracy in Python, preferably. Any pointers would be highly appreciated.
https://www.dropbox.com/s/orgr2yqhbbk2xnr/test.PNG
In the image above I'm trying to extract isovalue 25 from the scalar field of f(x,y)=x^3+y^3. I'm looking for 6 points with better accuracy than the 6 red points given by linear interpolation.
python matplotlib interpolation spline spatialinterpolation
this question edited Dec 2 '13 at 13:23 asked Dec 1 '13 at 13:45 Gustavo Chavez 66 1 6 1 I think that you want to smooth your data before you pass it to contour. Have you seen this post? stackoverflow.com/questions/12274529/… Scipy's griddata function might also be of interest if you are not starting with regularly spaced data: docs.scipy.org/doc/scipy/reference/generated/… – DanHickstein Dec 1 '13 at 22:51 Hmmm, I think that this question is probably a duplicate of this one: stackoverflow.com/questions/18402355/… (If not, add more detail to the question to clarify.) – DanHickstein Dec 1 '13 at 22:56 Smoothing is a good option, however it creates more points than needed, i.e. the vertices are not positioned in the edges of the scalar field. I'm looking for a more accurate interpolation at the edges (which linear interpolation does not give). Just edited the original post and add an image – Gustavo Chavez Dec 2 '13 at 13:20 also, higher order does not always mean more accurate en.wikipedia.org/wiki/Runge%27s_phenomenon Higher order also makes you very sensitive to noise. – tacaswell Dec 3 '13 at 2:17 Agree, but wouldn't be a reasonable choice to pick a 3rd order interpolation for a family of cubic implicit functions to get the best possible approximation? – Gustavo Chavez Dec 3 '13 at 5:24

1 Answers
1
For unstructured 2ddata (or triangulated data), you might be interested by the following class:
Recommend：python  Matplotlib: Data cubic interpolation (or FIT) for Contour plot
lot import matplotlib.pyplot as plta = [[1,1,1],[2,2,2],[3,3,3]]b = [[1,2,3],[1,2,3],[1,2,3]]c = [[3,2,1],[1,4,2],[4,5,1]]fig1 = plt.figure()ax1 = fig1.add_subplot(111)fig1.set_size_inches(3.54,3.54)#Create Contour plotcontour=ax
which provides a CloughTocher (cubic) interpolator from a userdefined Triangulation
and field defined at triangulation nodes. It can also be used through the helper class UniformTriRefiner
:
http://matplotlib.org/api/tri_api.html?highlight=refine_field#matplotlib.tri.UniformTriRefiner.refine_field http://matplotlib.org/mpl_examples/pylab_examples/tricontour_smooth_user.png
Nevertheless the choice of the adapted interpolation depends of course of your data set.

this answer answered Jan 19 '14 at 11:45 GBy 1,054 6 11 Hello there, thanks for the reply. I was aware of that routine but it's not quite what I'm looking for. I made a formal problem description on Latex in the current link in order to explain myself better: dropbox.com/s/f1hgzfgf0pyyqx1/Cubic%20Marching%20Squares.pdf – Gustavo Chavez Jan 19 '14 at 19:03 The restriction of the CubicTriInterpolator to one edge is a 3rd degree polynom ; you can easily get an analytical expression from the value of the function + derivatives at both ends. – GBy Jan 19 '14 at 20:43

Recommend：python  Interpolation differences on polar contour plots in Matplotlib
b to get some results. Out of curiosity I also wanted to try out the same thing in python using the matplotlib but somehow I am seeing different sets of contour plots for the same input data. I am trying to figure out whats going on and if