diff --git a/doc/api/api_changes/2017-11-31-AL.rst b/doc/api/api_changes/2017-11-31-AL.rst new file mode 100644 index 000000000000..8efa9a95c1df --- /dev/null +++ b/doc/api/api_changes/2017-11-31-AL.rst @@ -0,0 +1,5 @@ +Deprecations +```````````` + +The now unused ``mlab.less_simple_linear_interpolation`` function is +deprecated. diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index ecbde9ae91b5..f00b352e2077 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -417,25 +417,15 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5): else: dp = np.zeros_like(xi) - ll = mlab.less_simple_linear_interpolation(pl, slc, dp + xi, - extrap=True) - - # get vector in pixel space coordinates from one point to other - dd = np.diff(ll, axis=0).ravel() - - # Get angle of vector - must be calculated in pixel space for - # text rotation to work correctly - if np.all(dd == 0): # Must deal with case of zero length label - rotation = 0.0 - else: - rotation = np.rad2deg(np.arctan2(dd[1], dd[0])) + # Get angle of vector between the two ends of the label - must be + # calculated in pixel space for text rotation to work correctly. + (dx,), (dy,) = (np.diff(np.interp(dp + xi, pl, slc_col)) + for slc_col in slc.T) + rotation = np.rad2deg(np.arctan2(dy, dx)) if self.rightside_up: # Fix angle so text is never upside-down - if rotation > 90: - rotation = rotation - 180.0 - if rotation < -90: - rotation = 180.0 + rotation + rotation = (rotation + 90) % 180 - 90 # Break contour if desired nlc = [] @@ -443,37 +433,26 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5): # Expand range by spacing xi = dp + xi + np.array([-spacing, spacing]) - # Get indices near points of interest - I = mlab.less_simple_linear_interpolation( - pl, np.arange(len(pl)), xi, extrap=False) - - # If those indices aren't beyond contour edge, find x,y - if (not np.isnan(I[0])) and int(I[0]) != I[0]: - xy1 = mlab.less_simple_linear_interpolation( - pl, lc, [xi[0]]) - - if (not np.isnan(I[1])) and int(I[1]) != I[1]: - xy2 = mlab.less_simple_linear_interpolation( - pl, lc, [xi[1]]) - - # Round to integer values but keep as float - # To allow check against nan below - # Ignore nans here to avoid throwing an error on Appveyor build - # (can possibly be removed when build uses numpy 1.13) - with np.errstate(invalid='ignore'): - I = [np.floor(I[0]), np.ceil(I[1])] + # Get (integer) indices near points of interest; use -1 as marker + # for out of bounds. + I = np.interp(xi, pl, np.arange(len(pl)), left=-1, right=-1) + I = [np.floor(I[0]).astype(int), np.ceil(I[1]).astype(int)] + if I[0] != -1: + xy1 = [np.interp(xi[0], pl, lc_col) for lc_col in lc.T] + if I[1] != -1: + xy2 = [np.interp(xi[1], pl, lc_col) for lc_col in lc.T] # Actually break contours if closed: # This will remove contour if shorter than label - if np.all(~np.isnan(I)): - nlc.append(np.r_[xy2, lc[int(I[1]):int(I[0]) + 1], xy1]) + if np.all(I != -1): + nlc.append(np.row_stack([xy2, lc[I[1]:I[0]+1], xy1])) else: # These will remove pieces of contour if they have length zero - if not np.isnan(I[0]): - nlc.append(np.r_[lc[:int(I[0]) + 1], xy1]) - if not np.isnan(I[1]): - nlc.append(np.r_[xy2, lc[int(I[1]):]]) + if I[0] != -1: + nlc.append(np.row_stack([lc[:I[0]+1], xy1])) + if I[1] != -1: + nlc.append(np.row_stack([xy2, lc[I[1]:]])) # The current implementation removes contours completely # covered by labels. Uncomment line below to keep diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 3664e869814e..65a4885de923 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -3404,6 +3404,7 @@ def griddata(x, y, z, xi, yi, interp='nn'): ################################################## # Linear interpolation algorithms ################################################## +@cbook.deprecated("2.2", alternative="np.interp") def less_simple_linear_interpolation(x, y, xi, extrap=False): """ This function provides simple (but somewhat less so than diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index 5b33180af524..6a8aadaea997 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -122,7 +122,7 @@ def test_SimplePatchShadow_offset(): assert pe._offset == (4, 5) -@image_comparison(baseline_images=['collection'], tol=0.015) +@image_comparison(baseline_images=['collection'], tol=0.02) def test_collection(): x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100)) data = np.sin(x) + np.cos(y)