## SF.net SVN: matplotlib:[5824] trunk/matplotlib/lib/matplotlib/cbook.py

 SF.net SVN: matplotlib:[5824] trunk/matplotlib/lib/matplotlib/cbook.py From: - 2008-07-23 14:18:45 ```Revision: 5824 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5824&view=rev Author: dmkaplan Date: 2008-07-23 14:18:41 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Fix to is_scalar plus additional functions in cbook.py: less_simple_linear_interpolation isvector vector_lengths distances_along_curve path_length is_closed_polygon Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/cbook.py Modified: trunk/matplotlib/lib/matplotlib/cbook.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-23 13:28:32 UTC (rev 5823) +++ trunk/matplotlib/lib/matplotlib/cbook.py 2008-07-23 14:18:41 UTC (rev 5824) @@ -287,7 +287,7 @@ def is_scalar(obj): 'return true if *obj* is not string like and is not iterable' - return not is_string_like(obj) or not iterable(obj) + return not is_string_like(obj) and not iterable(obj) def is_numlike(obj): 'return true if *obj* looks like a number' @@ -1156,6 +1156,46 @@ return result +def less_simple_linear_interpolation( x, y, xi, extrap=False ): + """ + This function provides simple (but somewhat less so than + simple_linear_interpolation) linear interpolation. This is very + inefficient linear interpolation meant to be used only for a small + number of points in relatively non-intensive use cases. + + Call signature:: + + yi = less_simple_linear_interpolation(x,y,xi) + """ + if is_scalar(xi): xi = [xi] + + x = np.asarray(x) + y = np.asarray(y) + xi = np.asarray(xi) + + s = list(y.shape) + s[0] = len(xi) + yi = np.tile( np.nan, s ) + + for ii,xx in enumerate(xi): + bb = x == xx + if np.any(bb): + jj, = np.nonzero(bb) + yi[ii] = y[jj[0]] + elif xxx[-1]: + if extrap: + yi[ii] = y[-1] + else: + jj, = np.nonzero(x