@@ -337,8 +337,7 @@ def get_text(self, lev, fmt):
337337
338338 def locate_label (self , linecontour , labelwidth ):
339339 """
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).
342341 """
343342
344343 # Number of contour points
@@ -355,16 +354,15 @@ def locate_label(self, linecontour, labelwidth):
355354 XX = np .resize (linecontour [:, 0 ], (xsize , ysize ))
356355 YY = np .resize (linecontour [:, 1 ], (xsize , ysize ))
357356 # 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 :]
362361 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 )
364363 # Ignore warning that divide by zero throws, as this is a valid option
365364 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 )
368366 x , y , ind = self .get_label_coords (dist , XX , YY , ysize , labelwidth )
369367
370368 # There must be a more efficient way...
0 commit comments