@@ -548,9 +548,11 @@ def add_label_clabeltext(self, x, y, rotation, lev, cvalue):
548548 def add_label_near (self , x , y , inline = True , inline_spacing = 5 ,
549549 transform = None ):
550550 """
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.
554556
555557 *inline*:
556558 controls whether the underlying contour is removed or
@@ -569,19 +571,26 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
569571 if transform :
570572 x , y = transform .transform_point ((x , y ))
571573
574+ # find the nearest contour _in screen units_
572575 conmin , segmin , imin , xmin , ymin = self .find_nearest_contour (
573576 x , y , self .labelIndiceList )[:5 ]
574577
575578 # The calc_label_rot_and_inline routine requires that (xmin,ymin)
576579 # be a vertex in the path. So, if it isn't, add a vertex here
580+
581+ # grab the paths from the collections
577582 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
583590 if not np .allclose (xcmin , lc [imin ]):
591+ # insert new data into the vertex list
584592 lc = np .r_ [lc [:imin ], np .array (xcmin )[None , :], lc [imin :]]
593+ # replace the path with the new one
585594 paths [segmin ] = mpath .Path (lc )
586595
587596 # Get index of nearest level in subset of levels used for labeling
0 commit comments