scipy.interpolate.interp2d multivariate interpolation and list alignement

asked 2012-07-09 14:58:42 +0200

Cosmos gravatar image

updated 2015-01-22 21:32:34 +0200

FrédéricC gravatar image

Given a set of (x[i],y[i],Value[i]) we can create a list or tuple and plot them with the command list_plot3d. In this way we take a 3d plot where in fact the z-axis corresponds to the value of an f(x,y). Instead of doing this, it appears that with scipy.interpolate.interp2d it is possible to avoid using the list_plot3d and create a contour-density kind of plot. As shown in the link it is feasible to do this but the fact is that it is too complicated to understand for a beginner like me. Is possible to explain this just to the simple point that someone takes the tuple and tries to create a contour-like plot?


It seems that the part of the code below is enough to make a contour plot:

import numpy, scipy.interpolate 
f_interpolation = scipy.interpolate.interp2d(*zip(*data))
plot_interpolation = contour_plot(lambda x,y:
                   f_interpolation(x,y)[0], (30,40), (20,30), cmap='jet', contours=numpy.arange(0.1,30,5), colorbar=True)

Notice on the second line that it refers to some data obviously given before this part of the code. I found out that for this code to work one has to have fully aligned data to feed to the code above.


           ( 37.850629,  5.421135, 22.162571637111411),
           ( 37.706629,  0.421472,  5.229876952864690),
           (  7.706629, 28.421472, 15.229876952864690),

If in any way the data that might be a tuple, or a list from what i understand, are not formatted as above, the code doesn't run. How is it possible to right align all elements as well as keep them aligned in relation to the decimal place in a list?

edit retag flag offensive close merge delete