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