Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb07c42

Browse files
committed
Remove mlab.slopes, mlab.stineman_interp
1 parent 7ede68c commit fb07c42

3 files changed

Lines changed: 3 additions & 140 deletions

File tree

doc/api/next_api_changes/2018-09-18-DS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ in Matplotlib 2.2 has been removed. See below for a list:
2323
- `mlab.dist_point_to_segment`
2424
- `mlab.griddata` (use scipy.interpolate.griddata)
2525
- `mlab.less_simple_linear_interpolation` (use numpy.interp)
26+
- `mlab.slopes`
27+
- `mlab.stineman_interp`
2628
- `mlab.donothing_callback`

lib/matplotlib/mlab.py

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,145 +2556,6 @@ def newfunc(val, mask, mval):
25562556
fh.close()
25572557

25582558

2559-
##################################################
2560-
# Linear interpolation algorithms
2561-
##################################################
2562-
@cbook.deprecated("2.2")
2563-
def slopes(x, y):
2564-
"""
2565-
:func:`slopes` calculates the slope *y*'(*x*)
2566-
2567-
The slope is estimated using the slope obtained from that of a
2568-
parabola through any three consecutive points.
2569-
2570-
This method should be superior to that described in the appendix
2571-
of A CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russel
2572-
W. Stineman (Creative Computing July 1980) in at least one aspect:
2573-
2574-
Circles for interpolation demand a known aspect ratio between
2575-
*x*- and *y*-values. For many functions, however, the abscissa
2576-
are given in different dimensions, so an aspect ratio is
2577-
completely arbitrary.
2578-
2579-
The parabola method gives very similar results to the circle
2580-
method for most regular cases but behaves much better in special
2581-
cases.
2582-
2583-
Norbert Nemec, Institute of Theoretical Physics, University or
2584-
Regensburg, April 2006 Norbert.Nemec at physik.uni-regensburg.de
2585-
2586-
(inspired by a original implementation by Halldor Bjornsson,
2587-
Icelandic Meteorological Office, March 2006 halldor at vedur.is)
2588-
"""
2589-
# Cast key variables as float.
2590-
x = np.asarray(x, float)
2591-
y = np.asarray(y, float)
2592-
2593-
yp = np.zeros(y.shape, float)
2594-
2595-
dx = x[1:] - x[:-1]
2596-
dy = y[1:] - y[:-1]
2597-
dydx = dy/dx
2598-
yp[1:-1] = (dydx[:-1] * dx[1:] + dydx[1:] * dx[:-1])/(dx[1:] + dx[:-1])
2599-
yp[0] = 2.0 * dy[0]/dx[0] - yp[1]
2600-
yp[-1] = 2.0 * dy[-1]/dx[-1] - yp[-2]
2601-
return yp
2602-
2603-
2604-
@cbook.deprecated("2.2")
2605-
def stineman_interp(xi, x, y, yp=None):
2606-
"""
2607-
Given data vectors *x* and *y*, the slope vector *yp* and a new
2608-
abscissa vector *xi*, the function :func:`stineman_interp` uses
2609-
Stineman interpolation to calculate a vector *yi* corresponding to
2610-
*xi*.
2611-
2612-
Here's an example that generates a coarse sine curve, then
2613-
interpolates over a finer abscissa::
2614-
2615-
x = linspace(0,2*pi,20); y = sin(x); yp = cos(x)
2616-
xi = linspace(0,2*pi,40);
2617-
yi = stineman_interp(xi,x,y,yp);
2618-
plot(x,y,'o',xi,yi)
2619-
2620-
The interpolation method is described in the article A
2621-
CONSISTENTLY WELL BEHAVED METHOD OF INTERPOLATION by Russell
2622-
W. Stineman. The article appeared in the July 1980 issue of
2623-
Creative Computing with a note from the editor stating that while
2624-
they were:
2625-
2626-
not an academic journal but once in a while something serious
2627-
and original comes in adding that this was
2628-
"apparently a real solution" to a well known problem.
2629-
2630-
For *yp* = *None*, the routine automatically determines the slopes
2631-
using the :func:`slopes` routine.
2632-
2633-
*x* is assumed to be sorted in increasing order.
2634-
2635-
For values ``xi[j] < x[0]`` or ``xi[j] > x[-1]``, the routine
2636-
tries an extrapolation. The relevance of the data obtained from
2637-
this, of course, is questionable...
2638-
2639-
Original implementation by Halldor Bjornsson, Icelandic
2640-
Meteorolocial Office, March 2006 halldor at vedur.is
2641-
2642-
Completely reworked and optimized for Python by Norbert Nemec,
2643-
Institute of Theoretical Physics, University or Regensburg, April
2644-
2006 Norbert.Nemec at physik.uni-regensburg.de
2645-
"""
2646-
2647-
# Cast key variables as float.
2648-
x = np.asarray(x, float)
2649-
y = np.asarray(y, float)
2650-
if x.shape != y.shape:
2651-
raise ValueError("'x' and 'y' must be of same shape")
2652-
2653-
if yp is None:
2654-
yp = slopes(x, y)
2655-
else:
2656-
yp = np.asarray(yp, float)
2657-
2658-
xi = np.asarray(xi, float)
2659-
2660-
# calculate linear slopes
2661-
dx = x[1:] - x[:-1]
2662-
dy = y[1:] - y[:-1]
2663-
s = dy/dx # note length of s is N-1 so last element is #N-2
2664-
2665-
# find the segment each xi is in
2666-
# this line actually is the key to the efficiency of this implementation
2667-
idx = np.searchsorted(x[1:-1], xi)
2668-
2669-
# now we have generally: x[idx[j]] <= xi[j] <= x[idx[j]+1]
2670-
# except at the boundaries, where it may be that xi[j] < x[0] or
2671-
# xi[j] > x[-1]
2672-
2673-
# the y-values that would come out from a linear interpolation:
2674-
sidx = s.take(idx)
2675-
xidx = x.take(idx)
2676-
yidx = y.take(idx)
2677-
xidxp1 = x.take(idx+1)
2678-
yo = yidx + sidx * (xi - xidx)
2679-
2680-
# the difference that comes when using the slopes given in yp
2681-
# using the yp slope of the left point
2682-
dy1 = (yp.take(idx) - sidx) * (xi - xidx)
2683-
# using the yp slope of the right point
2684-
dy2 = (yp.take(idx+1)-sidx) * (xi - xidxp1)
2685-
2686-
dy1dy2 = dy1*dy2
2687-
# The following is optimized for Python. The solution actually
2688-
# does more calculations than necessary but exploiting the power
2689-
# of numpy, this is far more efficient than coding a loop by hand
2690-
# in Python
2691-
yi = yo + dy1dy2 * np.choose(np.array(np.sign(dy1dy2), np.int32)+1,
2692-
((2*xi-xidx-xidxp1)/((dy1-dy2)*(xidxp1-xidx)),
2693-
0.0,
2694-
1/(dy1+dy2),))
2695-
return yi
2696-
2697-
26982559
class GaussianKDE(object):
26992560
"""
27002561
Representation of a kernel-density estimate using Gaussian kernels.

lib/matplotlib/pylab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@
237237
l2norm, log2, movavg, norm_flat,
238238
path_length, poly_below, poly_between,
239239
rec2csv, rec_append_fields, rec_drop_fields, rec_join, rms_flat,
240-
segments_intersect, slopes, stineman_interp, vector_lengths,
240+
segments_intersect, vector_lengths,
241241
window_hanning, window_none)
242242

243243
from matplotlib import cbook, mlab, pyplot as plt

0 commit comments

Comments
 (0)