@@ -562,23 +562,38 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
562
562
exact for labels at locations where the contour is
563
563
straight, less so for labels on curved contours.
564
564
"""
565
-
565
+ # if 'do the default thing' use the axes data transform
566
566
if transform is None :
567
567
transform = self .ax .transData
568
568
569
+ # if transform is 'falsey' don't do any transform (this is a
570
+ # really awful API but is what we have)
569
571
if transform :
572
+ # The point of this transform is to get the location
573
+ # of label position into screen units
570
574
x , y = transform .transform_point ((x , y ))
571
575
576
+ # find the nearest contour _in screen units_
572
577
conmin , segmin , imin , xmin , ymin = self .find_nearest_contour (
573
578
x , y , self .labelIndiceList )[:5 ]
574
579
575
580
# The calc_label_rot_and_inline routine requires that (xmin,ymin)
576
581
# be a vertex in the path. So, if it isn't, add a vertex here
582
+
583
+ # grab the paths from the collections
577
584
paths = self .collections [conmin ].get_paths ()
578
- lc = paths [segmin ].vertices
585
+ # grab the correct segment
586
+ active_path = paths [segmin ]
587
+ # grab it's verticies
588
+ lc = active_path .vertices
589
+ # sort out where the new vertex should be added in the path's data
590
+ # units
579
591
xcmin = self .ax .transData .inverted ().transform_point ([xmin , ymin ])
592
+ # if there isn't a vertex close enough
580
593
if not np .allclose (xcmin , lc [imin ]):
594
+ # insert new data into the vertex list
581
595
lc = np .r_ [lc [:imin ], np .array (xcmin )[None , :], lc [imin :]]
596
+ # replace the path with the new one
582
597
paths [segmin ] = mpath .Path (lc )
583
598
584
599
# Get index of nearest level in subset of levels used for labeling
0 commit comments