floating point errors- arange

I found a bug in ticker.py, MultipleLocator.__call__:

locs = arange(vmin, vmax+0.001*self._base.get_base(), self._base.get_base())

I am running into some trouble with the arange function (imported from
matplotlib.numerix, and I have Numeric-23.8 installed).

When I do a=arange(-1,0.0001,.01), a[-1] is equal to something like 2e-17. I
wouldn't complain, but in this case, it will cause a tick to not be rendered
in a plot. Could somebody offer me some advice? I should mention that I don't
think I have the luxury of stepping through the array and checking each
value, because the responsiveness of matplotlib's interactive plots would be
adversely effected.

Thanks,
Darren

Darren Dale wrote:

I found a bug in ticker.py, MultipleLocator.__call__:

locs = arange(vmin, vmax+0.001*self._base.get_base(), self._base.get_base())

I am running into some trouble with the arange function (imported from matplotlib.numerix, and I have Numeric-23.8 installed).

When I do a=arange(-1,0.0001,.01), a[-1] is equal to something like 2e-17. I wouldn't complain, but in this case, it will cause a tick to not be rendered in a plot. Could somebody offer me some advice? I should mention that I don't think I have the luxury of stepping through the array and checking each value, because the responsiveness of matplotlib's interactive plots would be adversely effected.

You might want to use frange instead of arange. The frange implementation uses arange internally, but in the following way:

...
         # round() gets npts right even with the vagaries of floating point.
         npts=int(round((xfin-xini)/delta+endpoint))

     return arange(npts)*delta+xini

This approach makes it much more resilient against the problems of cumulative floating point addition error. Just notice that frange() defaults to closed intervals, so you may want to use the closed=0 flag.

Best,

f