I was working off of the example listed at
adapting it to my own data, and encountered the following error on MLAB
1.1.0, Python 2.7.2:
from numpy.random import uniform, seed
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
import numpy as np
# make up data.
#npts = int(raw_input('enter # of random points to plot:'))
npts = 200
x = uniform(-2,2,npts)
y = uniform(-2,2,npts)
z = x*np.exp(-x**2-y**2)
xi = np.linspace(0,60,100) # <= my xdata range
yi = np.linspace(0,0.9,200) # <= my ydata range
zi = griddata(x,y,z,xi,yi,interp='linear')
ValueError Traceback (most recent call last)
----> 1 zi = griddata(x,y,z,xi,yi,interp='linear')
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.
Can anyone else reproduce?
From: Paul Ivanov <pivanov314@gm...> - 2012-01-10 23:07:04
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
> 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:
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 : xi = np.linspace(0,603,100);dx =np.diff(xi); dx.ptp()
In : zi = griddata(x,y,z,xi,yi,interp='linear')
In : debug
2779 if dx.max()-dx.min() > epsx or
dy.max()-dy.min() > epsy:
-> 2780 raise ValueError("output grid must have
2781 " when using
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.
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7