@@ -289,6 +289,7 @@ def get_label_width(self, lev, fmt, fsize):
289
289
290
290
return lw
291
291
292
+ @cbook .deprecated ("2.2" )
292
293
def get_real_label_width (self , lev , fmt , fsize ):
293
294
"""
294
295
This computes actual onscreen label width.
@@ -336,8 +337,7 @@ def get_text(self, lev, fmt):
336
337
337
338
def locate_label (self , linecontour , labelwidth ):
338
339
"""
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).
341
341
"""
342
342
343
343
# Number of contour points
@@ -354,16 +354,15 @@ def locate_label(self, linecontour, labelwidth):
354
354
XX = np .resize (linecontour [:, 0 ], (xsize , ysize ))
355
355
YY = np .resize (linecontour [:, 1 ], (xsize , ysize ))
356
356
# 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 :]
361
361
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 )
363
363
# Ignore warning that divide by zero throws, as this is a valid option
364
364
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 )
367
366
x , y , ind = self .get_label_coords (dist , XX , YY , ysize , labelwidth )
368
367
369
368
# There must be a more efficient way...
0 commit comments