On 9 January 2013 09:32, Shahar Shani-Kadmiel <kadm...@post.bgu.ac.il>wrote:

> Hi,
>
> I'm trying to contour some data that I have and the griddata line fails. I
> tried running it on some synthetically generated data and I get the same
> IndexError. Any Ideas?
>
> Here is the example with the synthetic data:
>
> x = y = arange(-10,10,0.01)
>
> z = x**2+y**3
>
> xi = yi = linspace(-10.1, 10.1, 100)
>
> zi = griddata(x, y, z, xi, yi)
> ---------------------------------------------------------------------------
> IndexError                                Traceback (most recent call last)
> <ipython-input-52-0458ab6ea672> in <module>()
> ----> 1 zi = griddata(x, y, z, xi, yi)
>
> /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/mlab.py
> in griddata(x, y, z, xi, yi, interp)
>    2766             xi,yi = np.meshgrid(xi,yi)
>    2767         # triangulate data
> -> 2768         tri = delaunay.Triangulation(x,y)
>

Hello Shahar,

I think that your simple example is probably not what you intended.  Your
(x,y) points are all defined on the straight line from (-10,-10) to
(10,10).  The Delaunay triangulation of these points (which is what
griddata does) is not very interesting!  Perhaps you wanted (x,y) defined
on the 2D grid from (-10,-10) to (10,10), in which case you should follow
the x = y ... line with, for example:
    x, y = meshgrid(x, y)
(see numpy.meshgrid for further details).

You may still obtain the same IndexError, and the traceback shows this is
happening in the delaunay.Triangulation function call.  The matplotlib
delaunay package is not particularly robust, and can have problems handling
regularly-spaced data points.  The griddata documentation explains some of
this, see http://matplotlib.org/api/mlab_api.html#matplotlib.mlab.griddata.

To avoid the problem, the griddata documentation explains one possible way
that uses the natgrid algorithm.  A simpler solution that I often use is to
add a very small amount of noise to my regularly-spaced (x,y) points using
the numpy.random module.  I can give more details if you wish.

Ian
------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to