@@ -577,12 +577,12 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
577
577
paths = self .collections [conmin ].get_paths ()
578
578
lc = paths [segmin ].vertices
579
579
if transform :
580
- xcmin = transform .inverted ().transform ([xmin ,ymin ])
580
+ xcmin = transform .inverted ().transform ([xmin , ymin ])
581
581
else :
582
- xcmin = np .array ([xmin ,ymin ])
582
+ xcmin = np .array ([xmin , ymin ])
583
583
if not np .allclose (xcmin , lc [imin ]):
584
- lc = np .r_ [lc [:imin ], np .array (xcmin )[None ,:], lc [imin :]]
585
- paths [segmin ] = mpath .Path (lc )
584
+ lc = np .r_ [lc [:imin ], np .array (xcmin )[None , :], lc [imin :]]
585
+ paths [segmin ] = mpath .Path (lc )
586
586
587
587
# Get index of nearest level in subset of levels used for labeling
588
588
lmin = self .labelIndiceList .index (conmin )
@@ -685,6 +685,7 @@ def labels(self, inline, inline_spacing):
685
685
del paths [:]
686
686
paths .extend (additions )
687
687
688
+
688
689
def _find_closest_point_on_leg (p1 , p2 , p0 ):
689
690
'''find closest point to p0 on line segment connecting p1 and p2'''
690
691
@@ -698,37 +699,40 @@ def _find_closest_point_on_leg(p1, p2, p0):
698
699
699
700
# project on to line segment to find closest point
700
701
proj = np .dot (d01 , d21 ) / np .dot (d21 , d21 )
701
- if proj < 0 : proj = 0
702
- if proj > 1 : proj = 1
702
+ if proj < 0 :
703
+ proj = 0
704
+ if proj > 1 :
705
+ proj = 1
703
706
pc = p1 + proj * d21
704
707
705
708
# find squared distance
706
709
d = np .sum ((pc - p0 )** 2 )
707
710
708
711
return d , pc
709
712
713
+
710
714
def _find_closest_point_on_path (lc , point ):
711
715
'''
712
716
lc: coordinates of vertices
713
717
point: coordinates of test point
714
718
'''
715
719
716
720
# find index of closest vertex for this segment
717
- ds = np .sum ((lc - point [None ,:])** 2 , 1 )
721
+ ds = np .sum ((lc - point [None , :])** 2 , 1 )
718
722
imin = np .argmin (ds )
719
723
720
724
dmin = 1e10
721
725
xcmin = None
722
- legmin = (None ,None )
726
+ legmin = (None , None )
723
727
724
728
closed = mlab .is_closed_polygon (lc )
725
729
726
730
# build list of legs before and after this vertex
727
731
legs = []
728
732
if imin > 0 or closed :
729
- legs .append (((imin - 1 )% len (lc ),imin ))
733
+ legs .append (((imin - 1 ) % len (lc ), imin ))
730
734
if imin < len (lc ) - 1 or closed :
731
- legs .append ((imin ,(imin + 1 )% len (lc )))
735
+ legs .append ((imin , (imin + 1 ) % len (lc )))
732
736
733
737
for leg in legs :
734
738
d , xc = _find_closest_point_on_leg (lc [leg [0 ]], lc [leg [1 ]], point )
@@ -739,6 +743,7 @@ def _find_closest_point_on_path(lc, point):
739
743
740
744
return (dmin , xcmin , legmin )
741
745
746
+
742
747
class ContourSet (cm .ScalarMappable , ContourLabeler ):
743
748
"""
744
749
Store a set of contour lines or filled regions.
@@ -1327,7 +1332,7 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
1327
1332
xmin = None
1328
1333
ymin = None
1329
1334
1330
- point = np .array ([x ,y ])
1335
+ point = np .array ([x , y ])
1331
1336
1332
1337
for icon in indices :
1333
1338
con = self .collections [icon ]
0 commit comments