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

Skip to content

Commit b4e339a

Browse files
committed
Replace path_length in contour
1 parent d02024e commit b4e339a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/matplotlib/contour.py

Lines changed: 5 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,10 @@ 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+
# Calculate path lengths
404+
pl = np.zeros(slc.shape[0], dtype=float)
405+
dx = np.diff(slc, axis=0)
406+
pl[1:] = np.cumsum(np.hypot(dx[:, 0], dx[:, 1]))
405407
pl = pl - pl[ind]
406408

407409
# 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)