@@ -337,8 +337,7 @@ def get_text(self, lev, fmt):
337
337
338
338
def locate_label (self , linecontour , labelwidth ):
339
339
"""
340
- Find a good place to plot a label (relatively flat
341
- part of the contour).
340
+ Find good place to draw a label (relatively flat part of the contour).
342
341
"""
343
342
344
343
# Number of contour points
@@ -355,16 +354,15 @@ def locate_label(self, linecontour, labelwidth):
355
354
XX = np .resize (linecontour [:, 0 ], (xsize , ysize ))
356
355
YY = np .resize (linecontour [:, 1 ], (xsize , ysize ))
357
356
# I might have fouled up the following:
358
- yfirst = YY [:, 0 ]. reshape ( xsize , 1 )
359
- ylast = YY [:, - 1 ]. reshape ( xsize , 1 )
360
- xfirst = XX [:, 0 ]. reshape ( xsize , 1 )
361
- xlast = XX [:, - 1 ]. reshape ( xsize , 1 )
357
+ yfirst = YY [:, : 1 ]
358
+ ylast = YY [:, - 1 :]
359
+ xfirst = XX [:, : 1 ]
360
+ xlast = XX [:, - 1 :]
362
361
s = (yfirst - YY ) * (xlast - xfirst ) - (xfirst - XX ) * (ylast - yfirst )
363
- L = np .sqrt (( xlast - xfirst ) ** 2 + ( ylast - yfirst ) ** 2 ). ravel ( )
362
+ L = np .hypot ( xlast - xfirst , ylast - yfirst )
364
363
# Ignore warning that divide by zero throws, as this is a valid option
365
364
with np .errstate (divide = 'ignore' , invalid = 'ignore' ):
366
- dist = np .add .reduce ([(abs (s )[i ] / L [i ]) for i in range (xsize )],
367
- - 1 )
365
+ dist = np .sum (np .abs (s ) / L , axis = - 1 )
368
366
x , y , ind = self .get_label_coords (dist , XX , YY , ysize , labelwidth )
369
367
370
368
# There must be a more efficient way...
0 commit comments