Hi Brad,

Brad Malone, on 2011-12-19 19:06,  wrote:
> However, when I do my own data I get an error message that says:
> 
> > Traceback (most recent call last):
> >   File "make_colormap.py", line 248, in <module>
> >     zi=griddata(x,y,z,xi,yi,interp='linear')
> >   File "/usr/lib/pymodules/python2.6/matplotlib/mlab.py", line 2579, in
> > griddata
> >     raise ValueError("output grid must have constant spacing"
> > ValueError: output grid must have constant spacing when using
> > interp='linear'
...
 
> However, my code, when I do something like
> 
> > xi=linspace(-20.1,20.1,100)
> > yi=linspace(-20.1,20.1,200)
> > zi=griddata(x,y,z,xi,yi,interp='linear')
> > CS=plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
> 
> 
> it gives me the above error complaining about "constant spacing".
> 
> Anyone have an idea what I might be missing here? I can turn interp to 'nn'
> and the code works fine, but I'm just curious what about a "constant
> spaced" output grid I don't understand. Is it even possible to create a
> non-constant spaced output grid with linspace?

Looking at the code, it seems to be a floating point issue for
the way linspace works for the particular values you specified.
This should work for you, instead:

  xi=np.arange(-20.1,20.1+1e-14, 40.2/99)
  yi=np.arange(-20.1,20.1+1e-14,40.2/199)

NOTE: neither xi.max() nor yi.max() are "exactly" 20.1, the way
they were with linspace, nor is xi.max() exactly yi.max(). I say
"exactly" (in quotes) because when you type in 20.1, the floating point
number that you get isn't 20.10000000000000000000000000, it's
more like 20.10000000+change, in ipython, run '%precision 20' to
see what I mean.

Either the np.linspace or the mpl code likely needs to change,
because in mpl, the error gets raised when, effectively:

  dx = np.diff(xi)
  dx.max() - dx.min() > np.finfo(xi.dtype).resolution

and same for yi, which is what happens with the values you
provided to linspace, due to the way linspace works.

best,
-- 
Paul Ivanov
314 address only used for lists,  off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create 
new or port existing apps to sell to consumers worldwide. Explore the 
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to