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

Skip to content

Commit e9071ef

Browse files
committed
Some more deprecations
Delete _sqrt Fix up alternatives More deprecations of un-used methods Fix lots of deprecated decorators Fix amap docstring Remove test for _norm Revert change to np.linalg.norm (doesn't work on py2) Catch deprecations in tests Remove vector_lengths deprecation Replace path_length in contour Deprecate is_closed_polygon Replace bivariate normal in testing methods Deprecate griddata Move less_simple_linear_interpolation Move default format dict inside method Remove mlab from pylab Deprecated align_iterators in cbook Move contiguous_regions to cbook Remove some un-used mlab imports Replace dist in widgets.py Move pytest warning catchers
1 parent ba4142a commit e9071ef

File tree

10 files changed

+258
-130
lines changed

10 files changed

+258
-130
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
47934793
x, y1, y2 = np.broadcast_arrays(np.atleast_1d(x), y1, y2)
47944794

47954795
polys = []
4796-
for ind0, ind1 in mlab.contiguous_regions(where):
4796+
for ind0, ind1 in cbook.contiguous_regions(where):
47974797
xslice = x[ind0:ind1]
47984798
y1slice = y1[ind0:ind1]
47994799
y2slice = y2[ind0:ind1]
@@ -4952,7 +4952,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49524952
y, x1, x2 = np.broadcast_arrays(np.atleast_1d(y), x1, x2)
49534953

49544954
polys = []
4955-
for ind0, ind1 in mlab.contiguous_regions(where):
4955+
for ind0, ind1 in cbook.contiguous_regions(where):
49564956
yslice = y[ind0:ind1]
49574957
x1slice = x1[ind0:ind1]
49584958
x2slice = x2[ind0:ind1]

lib/matplotlib/cbook/__init__.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,48 @@ def simple_linear_interpolation(a, steps):
15771577
return result
15781578

15791579

1580+
def less_simple_linear_interpolation(x, y, xi, extrap=False):
1581+
"""
1582+
This function provides simple (but somewhat less so than
1583+
:func:`cbook.simple_linear_interpolation`) linear interpolation.
1584+
:func:`simple_linear_interpolation` will give a list of point
1585+
between a start and an end, while this does true linear
1586+
interpolation at an arbitrary set of points.
1587+
1588+
This is very inefficient linear interpolation meant to be used
1589+
only for a small number of points in relatively non-intensive use
1590+
cases. For real linear interpolation, use scipy.
1591+
"""
1592+
x = np.asarray(x)
1593+
y = np.asarray(y)
1594+
xi = np.atleast_1d(xi)
1595+
1596+
s = list(y.shape)
1597+
s[0] = len(xi)
1598+
yi = np.tile(np.nan, s)
1599+
1600+
for ii, xx in enumerate(xi):
1601+
bb = x == xx
1602+
if np.any(bb):
1603+
jj, = np.nonzero(bb)
1604+
yi[ii] = y[jj[0]]
1605+
elif xx < x[0]:
1606+
if extrap:
1607+
yi[ii] = y[0]
1608+
elif xx > x[-1]:
1609+
if extrap:
1610+
yi[ii] = y[-1]
1611+
else:
1612+
jj, = np.nonzero(x < xx)
1613+
jj = max(jj)
1614+
1615+
yi[ii] = (y[jj] +
1616+
(xx - x[jj]) / (x[jj + 1] - x[jj]) *
1617+
(y[jj + 1] - y[jj]))
1618+
1619+
return yi
1620+
1621+
15801622
@deprecated('2.1', alternative='shutil.rmtree')
15811623
def recursive_remove(path):
15821624
if os.path.isdir(path):
@@ -1936,6 +1978,7 @@ def unmasked_index_ranges(mask, compressed=True):
19361978
ls_mapper_r = {v: k for k, v in six.iteritems(ls_mapper)}
19371979

19381980

1981+
@deprecated('2.2')
19391982
def align_iterators(func, *iterables):
19401983
"""
19411984
This generator takes a bunch of iterables that are ordered by func
@@ -1980,6 +2023,32 @@ def __call__(self, key):
19802023
break
19812024

19822025

2026+
def contiguous_regions(mask):
2027+
"""
2028+
Return a list of (ind0, ind1) such that mask[ind0:ind1].all() is
2029+
True and we cover all such regions
2030+
"""
2031+
mask = np.asarray(mask, dtype=bool)
2032+
2033+
if not mask.size:
2034+
return []
2035+
2036+
# Find the indices of region changes, and correct offset
2037+
idx, = np.nonzero(mask[:-1] != mask[1:])
2038+
idx += 1
2039+
2040+
# List operations are faster for moderately sized arrays
2041+
idx = idx.tolist()
2042+
2043+
# Add first and/or last index if needed
2044+
if mask[0]:
2045+
idx = [0] + idx
2046+
if mask[-1]:
2047+
idx.append(len(mask))
2048+
2049+
return list(zip(idx[::2], idx[1::2]))
2050+
2051+
19832052
def is_math_text(s):
19842053
# Did we find an even number of non-escaped dollar signs?
19852054
# If so, treat is as math text.

lib/matplotlib/collections.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from matplotlib.artist import allow_rasterization
3333
import matplotlib.path as mpath
3434
from matplotlib import _path
35-
import matplotlib.mlab as mlab
3635
import matplotlib.lines as mlines
3736

3837
CIRCLE_AREA_FACTOR = 1.0 / np.sqrt(np.pi)
@@ -1052,7 +1051,7 @@ def span_where(x, ymin, ymax, where, **kwargs):
10521051
passed on to the collection.
10531052
"""
10541053
xranges = []
1055-
for ind0, ind1 in mlab.contiguous_regions(where):
1054+
for ind0, ind1 in cbook.contiguous_regions(where):
10561055
xslice = x[ind0:ind1]
10571056
if not len(xslice):
10581057
continue

lib/matplotlib/contour.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import matplotlib.font_manager as font_manager
2222
import matplotlib.text as text
2323
import matplotlib.cbook as cbook
24-
import matplotlib.mlab as mlab
2524
import matplotlib.mathtext as mathtext
2625
import matplotlib.patches as mpatches
2726
import matplotlib.texmanager as texmanager
@@ -382,7 +381,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
382381
not empty (lc defaults to the empty list if None). *spacing*
383382
is the space around the label in pixels to leave empty.
384383
385-
Do both of these tasks at once to avoid calling mlab.path_length
384+
Do both of these tasks at once to avoid calculating path lengths
386385
multiple times, which is relatively costly.
387386
388387
The method used here involves calculating the path length
@@ -397,7 +396,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
397396
hlw = lw / 2.0
398397

399398
# Check if closed and, if so, rotate contour so label is at edge
400-
closed = mlab.is_closed_polygon(slc)
399+
closed = _is_closed_polygon(slc)
401400
if closed:
402401
slc = np.r_[slc[ind:-1], slc[:ind + 1]]
403402

@@ -406,8 +405,10 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
406405

407406
ind = 0
408407

409-
# Path length in pixel space
410-
pl = mlab.path_length(slc)
408+
# Calculate path lengths
409+
pl = np.zeros(slc.shape[0], dtype=float)
410+
dx = np.diff(slc, axis=0)
411+
pl[1:] = np.cumsum(np.hypot(dx[:, 0], dx[:, 1]))
411412
pl = pl - pl[ind]
412413

413414
# Use linear interpolation to get points around label
@@ -417,8 +418,8 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
417418
else:
418419
dp = np.zeros_like(xi)
419420

420-
ll = mlab.less_simple_linear_interpolation(pl, slc, dp + xi,
421-
extrap=True)
421+
ll = cbook.less_simple_linear_interpolation(pl, slc, dp + xi,
422+
extrap=True)
422423

423424
# get vector in pixel space coordinates from one point to other
424425
dd = np.diff(ll, axis=0).ravel()
@@ -444,16 +445,16 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
444445
xi = dp + xi + np.array([-spacing, spacing])
445446

446447
# Get indices near points of interest
447-
I = mlab.less_simple_linear_interpolation(
448+
I = cbook.less_simple_linear_interpolation(
448449
pl, np.arange(len(pl)), xi, extrap=False)
449450

450451
# If those indices aren't beyond contour edge, find x,y
451452
if (not np.isnan(I[0])) and int(I[0]) != I[0]:
452-
xy1 = mlab.less_simple_linear_interpolation(
453+
xy1 = cbook.less_simple_linear_interpolation(
453454
pl, lc, [xi[0]])
454455

455456
if (not np.isnan(I[1])) and int(I[1]) != I[1]:
456-
xy2 = mlab.less_simple_linear_interpolation(
457+
xy2 = cbook.less_simple_linear_interpolation(
457458
pl, lc, [xi[1]])
458459

459460
# Round to integer values but keep as float
@@ -650,7 +651,7 @@ def labels(self, inline, inline_spacing):
650651
# zero in print_label and locate_label. Other than these
651652
# functions, this is not necessary and should probably be
652653
# eventually removed.
653-
if mlab.is_closed_polygon(lc):
654+
if _is_closed_polygon(lc):
654655
slc = np.r_[slc0, slc0[1:2, :]]
655656
else:
656657
slc = slc0
@@ -711,6 +712,15 @@ def _find_closest_point_on_leg(p1, p2, p0):
711712
return d, pc
712713

713714

715+
def _is_closed_polygon(X):
716+
"""
717+
Tests whether first and last object in a sequence are the same. These are
718+
presumably coordinates on a polygonal curve, in which case this function
719+
tests if that curve is closed.
720+
"""
721+
return np.all(X[0] == X[-1])
722+
723+
714724
def _find_closest_point_on_path(lc, point):
715725
"""
716726
lc: coordinates of vertices
@@ -725,7 +735,7 @@ def _find_closest_point_on_path(lc, point):
725735
xcmin = None
726736
legmin = (None, None)
727737

728-
closed = mlab.is_closed_polygon(lc)
738+
closed = _is_closed_polygon(lc)
729739

730740
# build list of legs before and after this vertex
731741
legs = []

0 commit comments

Comments
 (0)