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

Skip to content

Commit f635179

Browse files
committed
Replace mlab functions in contour labelling
1 parent d02024e commit f635179

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/matplotlib/contour.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
376376
not empty (lc defaults to the empty list if None). *spacing*
377377
is the space around the label in pixels to leave empty.
378378
379-
Do both of these tasks at once to avoid calling mlab.path_length
379+
Do both of these tasks at once to avoid calculating path lengths
380380
multiple times, which is relatively costly.
381381
382382
The method used here involves calculating the path length
@@ -400,8 +400,11 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
400400

401401
ind = 0
402402

403-
# Path length in pixel space
404-
pl = mlab.path_length(slc)
403+
def _path_length(X):
404+
dX = np.diff(X, axis=0)
405+
dX = np.linalg.norm(dX, axis=1)
406+
return np.concatenate((np.zeros(1), np.cumsum(dX)))
407+
pl = _path_length(slc)
405408
pl = pl - pl[ind]
406409

407410
# Use linear interpolation to get points around label

lib/matplotlib/mlab.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,7 @@ def cross_from_above(x, threshold):
39113911
##################################################
39123912
# Vector and path length geometry calculations
39133913
##################################################
3914+
@cbook.deprecated('2.2')
39143915
def vector_lengths(X, P=2., axis=None):
39153916
"""
39163917
Finds the length of a set of vectors in *n* dimensions. This is
@@ -3925,6 +3926,7 @@ def vector_lengths(X, P=2., axis=None):
39253926
return (np.sum(X**(P), axis=axis))**(1./P)
39263927

39273928

3929+
@cbook.deprecated('2.2')
39283930
def distances_along_curve(X):
39293931
"""
39303932
Computes the distance between a set of successive points in *N* dimensions.
@@ -3937,6 +3939,7 @@ def distances_along_curve(X):
39373939
return vector_lengths(X, axis=1)
39383940

39393941

3942+
@cbook.deprecated('2.2')
39403943
def path_length(X):
39413944
"""
39423945
Computes the distance travelled along a polygonal curve in *N* dimensions.

0 commit comments

Comments
 (0)