Thanks for the report, Ethan,

Ethan Swint, on 2012-01-10 16:34,  wrote:
> Can anyone else reproduce?

Confirming, this is a bug. We need to change the matplotlib code,
but I'm not sure how to proceed. I've filed it as the ominously
numbered matplotlib issue #666

https://github.com/matplotlib/matplotlib/issues/666

> It seems that 'xi,yi = np.meshgrid(xi,yi)' from line 2766 of mlab.py 
> doesn't always produce uniformly spaced data, as the test for uniform 
> data fails at line 2779.  Ignoring the error, however, results in 
> satisfactory evaluation of interp() on 2783.

That's not quite the issue here, as meshgrid simply reshapes and
repeats the data that you hand it. 

At first I was going to blame linspace, because a similar issue
came up on this list late last year, and in that example, simply
using arange instead of linspace resolved the issue:

http://old.nabble.com/constant-spacing-with-griddata-td33007330.html#a33007330

There, I considered the possibility that either (or both) the
numpy and mpl code should be changed. 

With your example, I'm convinced now the MPL code needs to
change, since here, linspace and arange produce identical
results. The reason I'm not sure how to proceed is that the
difference between dx.max() and dx.min() can be an order of
magnitude greater than the epsx value it is compared against.
Here's a modification to your example that does this

  In [155]: xi = np.linspace(0,603,100);dx =np.diff(xi); dx.ptp()
  Out[155]: 0.00000000000011368684
  
  In [157]: zi = griddata(x,y,z,xi,yi,interp='linear')
  --error--
  In [158]: debug
  > 
/home/pi/usr/local/lib/python2.6/site-packages/matplotlib/mlab.py(2780)griddata()
     2779             if dx.max()-dx.min() > epsx or
  dy.max()-dy.min() > epsy:
  -> 2780                 raise ValueError("output grid must have
  constant spacing"
     2781                                  " when using
  interp='linear'")
  
  ipdb> dx.ptp()
  1.1368683772161603e-13
  ipdb> epsx
  1.0000000000000001e-15
  ipdb> 

I believe that this has to do with the limited precision and
non-uniformity of the possible numbers represented by the
floating point standard. The check for constant spacing likely
should take into account and compare dx.ptp() to the average dx
itself, or something like that.

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