@@ -548,9 +548,11 @@ def add_label_clabeltext(self, x, y, rotation, lev, cvalue):
548
548
def add_label_near (self , x , y , inline = True , inline_spacing = 5 ,
549
549
transform = None ):
550
550
"""
551
- Add a label near the point (x, y) of the given transform.
552
- If transform is None, data transform is used. If transform is
553
- False, IdentityTransform is used.
551
+ Add a label near the point (x, y). If transform is None
552
+ (default), (x, y) is in data coordinates; if transform is
553
+ False, (x, y) is in display coordinates; otherwise, the
554
+ specified transform will be used to translate (x, y) into
555
+ display coordinates.
554
556
555
557
*inline*:
556
558
controls whether the underlying contour is removed or
@@ -569,19 +571,26 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
569
571
if transform :
570
572
x , y = transform .transform_point ((x , y ))
571
573
574
+ # find the nearest contour _in screen units_
572
575
conmin , segmin , imin , xmin , ymin = self .find_nearest_contour (
573
576
x , y , self .labelIndiceList )[:5 ]
574
577
575
578
# The calc_label_rot_and_inline routine requires that (xmin,ymin)
576
579
# be a vertex in the path. So, if it isn't, add a vertex here
580
+
581
+ # grab the paths from the collections
577
582
paths = self .collections [conmin ].get_paths ()
578
- lc = paths [segmin ].vertices
579
- if transform :
580
- xcmin = transform .inverted ().transform ([xmin , ymin ])
581
- else :
582
- xcmin = np .array ([xmin , ymin ])
583
+ # grab the correct segment
584
+ active_path = paths [segmin ]
585
+ # grab it's verticies
586
+ lc = active_path .vertices
587
+ # sort out where the new vertex should be added data-units
588
+ xcmin = self .ax .transData .inverted ().transform_point ([xmin , ymin ])
589
+ # if there isn't a vertex close enough
583
590
if not np .allclose (xcmin , lc [imin ]):
591
+ # insert new data into the vertex list
584
592
lc = np .r_ [lc [:imin ], np .array (xcmin )[None , :], lc [imin :]]
593
+ # replace the path with the new one
585
594
paths [segmin ] = mpath .Path (lc )
586
595
587
596
# Get index of nearest level in subset of levels used for labeling
0 commit comments