@@ -61,6 +61,9 @@ class Legend(Artist):
6161 'upper center' : 9,
6262 'center' : 10,
6363
64+ loc can be a tuple of the noramilzed coordinate values with
65+ respect its parent.
66+
6467 Return value is a sequence of text, line instances that make
6568 up the legend
6669 """
@@ -100,7 +103,7 @@ def __init__(self, parent, handles, labels,
100103 axespad = None , # deprecated; use borderaxespad
101104
102105 # spacing & pad defined as a fractionof the font-size
103- borderpad = None , # the fractional whitespace inside the legend border
106+ borderpad = None , # the whitespace inside the legend border
104107 labelspacing = None , #the vertical space between the legend entries
105108 handlelength = None , # the length of the legend handles
106109 handletextpad = None , # the pad between the legend handle and text
@@ -119,11 +122,11 @@ def __init__(self, parent, handles, labels,
119122
120123 Optional keyword arguments:
121124
122- ================ =========================================
125+ ================ =================================================
123126 Keyword Description
124- ================ =========================================
127+ ================ =================================================
125128
126- loc a location code
129+ loc a location code or a tuple of coordinates
127130 numpoints the number of points in the legend line
128131 prop the font property
129132 markerscale the relative size of legend markers vs. original
@@ -284,14 +287,22 @@ def _set_artist_props(self, a):
284287 a .set_transform (self .get_transform ())
285288
286289 def _findoffset_best (self , width , height , xdescent , ydescent ):
287- "Heper function to locate the legend"
290+ "Heper function to locate the legend at its best position "
288291 ox , oy = self ._find_best_position (width , height )
289292 return ox + xdescent , oy + ydescent
290293
291294 def _findoffset_loc (self , width , height , xdescent , ydescent ):
292- "Heper function to locate the legend"
293- bbox = Bbox .from_bounds (0 , 0 , width , height )
294- x , y = self ._get_anchored_bbox (self ._loc , bbox , self .parent .bbox )
295+ "Heper function to locate the legend using the location code"
296+
297+ if iterable (self ._loc ) and len (self ._loc )== 2 :
298+ # when loc is a tuple of axes(or figure) coordinates.
299+ fx , fy = self ._loc
300+ bbox = self .parent .bbox
301+ x , y = bbox .x0 + bbox .width * fx , bbox .y0 + bbox .height * fy
302+ else :
303+ bbox = Bbox .from_bounds (0 , 0 , width , height )
304+ x , y = self ._get_anchored_bbox (self ._loc , bbox , self .parent .bbox )
305+
295306 return x + xdescent , y + ydescent
296307
297308 def draw (self , renderer ):
0 commit comments