@@ -553,9 +553,11 @@ def add_label_clabeltext(self, x, y, rotation, lev, cvalue):
553553 def add_label_near (self , x , y , inline = True , inline_spacing = 5 ,
554554 transform = None ):
555555 """
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.
559561
560562 *inline*:
561563 controls whether the underlying contour is removed or
@@ -574,19 +576,26 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
574576 if transform :
575577 x , y = transform .transform_point ((x , y ))
576578
579+ # find the nearest contour _in screen units_
577580 conmin , segmin , imin , xmin , ymin = self .find_nearest_contour (
578581 x , y , self .labelIndiceList )[:5 ]
579582
580583 # The calc_label_rot_and_inline routine requires that (xmin,ymin)
581584 # be a vertex in the path. So, if it isn't, add a vertex here
585+
586+ # grab the paths from the collections
582587 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
588595 if not np .allclose (xcmin , lc [imin ]):
596+ # insert new data into the vertex list
589597 lc = np .r_ [lc [:imin ], np .array (xcmin )[None , :], lc [imin :]]
598+ # replace the path with the new one
590599 paths [segmin ] = mpath .Path (lc )
591600
592601 # Get index of nearest level in subset of levels used for labeling
0 commit comments