lib/matplotlib/text.py
def _update_position_xytext(self, renderer, xy_pixel):
        "Update the pixel positions of the annotation text and the arrow patch."

        x, y = self.xytext
        self._x, self._y = self._get_xy(x, y, self.textcoords)


        x, y = xy_pixel

        ox0, oy0 = self._x, self._y
        ox1, oy1 = x, y

        if self.arrowprops:
            x0, y0 = x, y
            l,b,w,h = self.get_window_extent(renderer).bounds
            r = l+w
            t = b+h
            xc = 0.5*(l+r)
            yc = 0.5*(b+t)

            d = self.arrowprops.copy()

            # Use FancyArrowPatch if self.arrowprops has "arrowstyle" key.
            # Otherwise, fallback to YAArrow.

            #if d.has_key("arrowstyle"):
            if self.arrow_patch:

                # adjust the starting point of the arrow relative to
                # the textbox.
                # TODO : Rotation needs to be accounted.
                relpos = self._arrow_relpos
                bbox = self.get_window_extent(renderer)
                ox0 = bbox.x0 + bbox.width * relpos[0]
                oy0 = bbox.y0 + bbox.height * relpos[1]

                # The arrow will be drawn from (ox0, oy0) to (ox1,
                # oy1). It will be first clipped by patchA and patchB.
                # Then it will be shrinked by shirnkA and shrinkB
                # (in points). If patch A is not set, self.bbox_patch
                # is used.

                self.arrow_patch.set_positions((ox0, oy0), (ox1,oy1))
                mutation_scale = d.pop("mutation_scale", self.get_size())
                mutation_scale = renderer.points_to_pixels(mutation_scale)
                self.arrow_patch.set_mutation_scale(mutation_scale)

                if self._bbox_patch:
                    patchA = d.pop("patchA", self._bbox_patch)
                    self.arrow_patch.set_patchA(patchA)
                else:
                    patchA = d.pop("patchA", self._bbox)
                    self.arrow_patch.set_patchA(patchA)

            else:

                # pick the x,y corner of the text bbox closest to point
                # annotated
                dsu = [(abs(val-x0), val) for val in l, r, xc]
                dsu.sort()
                _, x = dsu[0]

                dsu = [(abs(val-y0), val) for val in b, t, yc]
                dsu.sort()
                _, y = dsu[0]

                shrink = d.pop('shrink', 0.0)

                theta = math.atan2(y-y0, x-x0)
                r = math.sqrt((y-y0)**2. + (x-x0)**2.)
                dx = shrink*r*math.cos(theta)
                dy = shrink*r*math.sin(theta)

                width = d.pop('width', 4)
                headwidth = d.pop('headwidth', 12)
                frac = d.pop('frac', 0.1)

                self.arrow = YAArrow(self.figure, (x0+dx,y0+dy), (x-dx, y-dy),
                                     width=width, headwidth=headwidth, frac=frac,
                                     **d)

                self.arrow.set_clip_box(self.get_clip_box())
Update the pixel positions of the annotation text and the arrow patch.
Update the pixel positions of the annotation text and the arrow patch.
Update the pixel positions of the annotation text and the arrow patch .
def _update_position_xytext(self, renderer, xy_pixel):
        x, y = self.xytext
        self._x, self._y = self._get_xy(x, y, self.textcoords)
        x, y = xy_pixel
        ox0, oy0 = self._x, self._y
        ox1, oy1 = x, y
        if self.arrowprops:
            x0, y0 = x, y
            l,b,w,h = self.get_window_extent(renderer).bounds
            r = l+w
            t = b+h
            xc = 0.5*(l+r)
            yc = 0.5*(b+t)
            d = self.arrowprops.copy()
            if self.arrow_patch:
                relpos = self._arrow_relpos
                bbox = self.get_window_extent(renderer)
                ox0 = bbox.x0 + bbox.width * relpos[0]
                oy0 = bbox.y0 + bbox.height * relpos[1]
                self.arrow_patch.set_positions((ox0, oy0), (ox1,oy1))
                mutation_scale = d.pop("mutation_scale", self.get_size())
                mutation_scale = renderer.points_to_pixels(mutation_scale)
                self.arrow_patch.set_mutation_scale(mutation_scale)
                if self._bbox_patch:
                    patchA = d.pop("patchA", self._bbox_patch)
                    self.arrow_patch.set_patchA(patchA)
                else:
                    patchA = d.pop("patchA", self._bbox)
                    self.arrow_patch.set_patchA(patchA)
            else:
                dsu = [(abs(val-x0), val) for val in l, r, xc]
                dsu.sort()
                _, x = dsu[0]
                dsu = [(abs(val-y0), val) for val in b, t, yc]
                dsu.sort()
                _, y = dsu[0]
                shrink = d.pop('shrink', 0.0)
                theta = math.atan2(y-y0, x-x0)
                r = math.sqrt((y-y0)**2. + (x-x0)**2.)
                dx = shrink*r*math.cos(theta)
                dy = shrink*r*math.sin(theta)
                width = d.pop('width', 4)
                headwidth = d.pop('headwidth', 12)
                frac = d.pop('frac', 0.1)
                self.arrow = YAArrow(self.figure, (x0+dx,y0+dy), (x-dx, y-dy),
                                     width=width, headwidth=headwidth, frac=frac,
                                     **d)
                self.arrow.set_clip_box(self.get_clip_box())
def _update_position_xytext ( self , renderer , xy_pixel ) : x , y = self . xytext self . _x , self . _y = self . _get_xy ( x , y , self . textcoords ) x , y = xy_pixel ox0 , oy0 = self . _x , self . _y ox1 , oy1 = x , y if self . arrowprops : x0 , y0 = x , y l , b , w , h = self . get_window_extent ( renderer ) . bounds r = l + w t = b + h xc = 0.5 * ( l + r ) yc = 0.5 * ( b + t ) d = self . arrowprops . copy ( ) if self . arrow_patch : relpos = self . _arrow_relpos bbox = self . get_window_extent ( renderer ) ox0 = bbox . x0 + bbox . width * relpos [ 0 ] oy0 = bbox . y0 + bbox . height * relpos [ 1 ] self . arrow_patch . set_positions ( ( ox0 , oy0 ) , ( ox1 , oy1 ) ) mutation_scale = d . pop ( "mutation_scale" , self . get_size ( ) ) mutation_scale = renderer . points_to_pixels ( mutation_scale ) self . arrow_patch . set_mutation_scale ( mutation_scale ) if self . _bbox_patch : patchA = d . pop ( "patchA" , self . _bbox_patch ) self . arrow_patch . set_patchA ( patchA ) else : patchA = d . pop ( "patchA" , self . _bbox ) self . arrow_patch . set_patchA ( patchA ) else : dsu = [ ( abs ( val - x0 ) , val ) for val in l , r , xc ] dsu . sort ( ) _ , x = dsu [ 0 ] dsu = [ ( abs ( val - y0 ) , val ) for val in b , t , yc ] dsu . sort ( ) _ , y = dsu [ 0 ] shrink = d . pop ( 'shrink' , 0.0 ) theta = math . atan2 ( y - y0 , x - x0 ) r = math . sqrt ( ( y - y0 ) ** 2. + ( x - x0 ) ** 2. ) dx = shrink * r * math . cos ( theta ) dy = shrink * r * math . sin ( theta ) width = d . pop ( 'width' , 4 ) headwidth = d . pop ( 'headwidth' , 12 ) frac = d . pop ( 'frac' , 0.1 ) self . arrow = YAArrow ( self . figure , ( x0 + dx , y0 + dy ) , ( x - dx , y - dy ) , width = width , headwidth = headwidth , frac = frac , ** d ) self . arrow . set_clip_box ( self . get_clip_box ( ) )
Update the pixel positions of the annotation text and the arrow patch.
Update the pixel positions of the annotation text and the arrow patch .
"Update the pixel positions of the annotation text and the arrow patch." # Use FancyArrowPatch if self.arrowprops has "arrowstyle" key. # Otherwise, fallback to YAArrow. #if d.has_key("arrowstyle"): # adjust the starting point of the arrow relative to # the textbox. # TODO : Rotation needs to be accounted. # The arrow will be drawn from (ox0, oy0) to (ox1, # oy1). It will be first clipped by patchA and patchB. # Then it will be shrinked by shirnkA and shrinkB # (in points). If patch A is not set, self.bbox_patch # is used. # pick the x,y corner of the text bbox closest to point # annotated
self
renderer
xy_pixel