Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 561988f

Browse files
committed
Fixed a bug in the new legend class that didn't allowed a tuple of coordinate vlaues as loc
svn path=/trunk/matplotlib/; revision=6479
1 parent 2562f8e commit 561988f

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2008-12-02 Fixed a bug in the new legend class that didn't allowed
2+
a tuple of coordinate vlaues as loc. -JJL
3+
14
2008-12-02 Improve checks for external dependencies, using subprocess
25
(instead of deprecated popen*) and distutils (for version
36
checking) - DSD

lib/matplotlib/legend.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)