@@ -289,6 +289,7 @@ def get_label_width(self, lev, fmt, fsize):
289289
290290 return lw
291291
292+ @cbook .deprecated ("2.2" )
292293 def get_real_label_width (self , lev , fmt , fsize ):
293294 """
294295 This computes actual onscreen label width.
@@ -336,8 +337,7 @@ def get_text(self, lev, fmt):
336337
337338 def locate_label (self , linecontour , labelwidth ):
338339 """
339- Find a good place to plot a label (relatively flat
340- part of the contour).
340+ Find good place to draw a label (relatively flat part of the contour).
341341 """
342342
343343 # Number of contour points
@@ -354,16 +354,15 @@ def locate_label(self, linecontour, labelwidth):
354354 XX = np .resize (linecontour [:, 0 ], (xsize , ysize ))
355355 YY = np .resize (linecontour [:, 1 ], (xsize , ysize ))
356356 # I might have fouled up the following:
357- yfirst = YY [:, 0 ]. reshape ( xsize , 1 )
358- ylast = YY [:, - 1 ]. reshape ( xsize , 1 )
359- xfirst = XX [:, 0 ]. reshape ( xsize , 1 )
360- xlast = XX [:, - 1 ]. reshape ( xsize , 1 )
357+ yfirst = YY [:, : 1 ]
358+ ylast = YY [:, - 1 :]
359+ xfirst = XX [:, : 1 ]
360+ xlast = XX [:, - 1 :]
361361 s = (yfirst - YY ) * (xlast - xfirst ) - (xfirst - XX ) * (ylast - yfirst )
362- L = np .sqrt (( xlast - xfirst ) ** 2 + ( ylast - yfirst ) ** 2 ). ravel ( )
362+ L = np .hypot ( xlast - xfirst , ylast - yfirst )
363363 # Ignore warning that divide by zero throws, as this is a valid option
364364 with np .errstate (divide = 'ignore' , invalid = 'ignore' ):
365- dist = np .add .reduce ([(abs (s )[i ] / L [i ]) for i in range (xsize )],
366- - 1 )
365+ dist = np .sum (np .abs (s ) / L , axis = - 1 )
367366 x , y , ind = self .get_label_coords (dist , XX , YY , ysize , labelwidth )
368367
369368 # There must be a more efficient way...
0 commit comments