Skip to content

Commit

Permalink
implement handleheight parameter for legend. This addresses matplotli…
Browse files Browse the repository at this point in the history
  • Loading branch information
leejjoon committed Jul 28, 2011
1 parent ae1e230 commit e5e3369
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions lib/matplotlib/legend.py
Expand Up @@ -146,6 +146,7 @@ def __init__(self, parent, handles, labels,
borderpad = None, # the whitespace inside the legend border
labelspacing=None, #the vertical space between the legend entries
handlelength=None, # the length of the legend handles
handleheight=None, # the height of the legend handles
handletextpad=None, # the pad between the legend handle and text
borderaxespad=None, # the pad between the axes and legend border
columnspacing=None, # spacing between columns
Expand Down Expand Up @@ -184,6 +185,7 @@ def __init__(self, parent, handles, labels,
borderpad the fractional whitespace inside the legend border
labelspacing the vertical space between the legend entries
handlelength the length of the legend handles
handleheight the length of the legend handles
handletextpad the pad between the legend handle and text
borderaxespad the pad between the axes and legend border
columnspacing the spacing between columns
Expand Down Expand Up @@ -223,7 +225,7 @@ def __init__(self, parent, handles, labels,
self._fontsize = self.prop.get_size_in_points()

propnames=['numpoints', 'markerscale', 'shadow', "columnspacing",
"scatterpoints"]
"scatterpoints", "handleheight"]

self.texts = []
self.legendHandles = []
Expand Down Expand Up @@ -585,9 +587,9 @@ def _init_legend_box(self, handles, labels):

# The approximate height and descent of text. These values are
# only used for plotting the legend handle.
height = self._approx_text_height() * 0.7
descent = 0.

descent = 0.35*self._approx_text_height()*(self.handleheight - 0.7)
# 0.35 and 0.7 are just heuristic numbers. this may need to be improbed
height = self._approx_text_height() * self.handleheight - descent
# each handle needs to be drawn inside a box of (x, y, w, h) =
# (0, -descent, width, height). And their corrdinates should
# be given in the display coordinates.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend_handler.py
Expand Up @@ -231,7 +231,7 @@ def _create_patch(self, legend, orig_handle,
xdescent, ydescent, width, height, fontsize):
if self._patch_func is None:
p = Rectangle(xy=(-xdescent, -ydescent),
width = width+xdescent, height=(height+ydescent))
width = width, height=height)
else:
p = self._patch_func(legend=legend, orig_handle=orig_handle,
xdescent=xdescent, ydescent=ydescent,
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/rcsetup.py
Expand Up @@ -472,6 +472,7 @@ def __call__(self, s):
'legend.borderpad' : [0.4, validate_float], # units are fontsize
'legend.labelspacing' : [0.5, validate_float], # the vertical space between the legend entries
'legend.handlelength' : [2., validate_float], # the length of the legend lines
'legend.handleheight' : [0.7, validate_float], # the length of the legend lines
'legend.handletextpad' : [.8, validate_float], # the space between the legend line and legend text
'legend.borderaxespad' : [0.5, validate_float], # the border between the axes and legend edge
'legend.columnspacing' : [2., validate_float], # the border between the axes and legend edge
Expand Down

0 comments on commit e5e3369

Please sign in to comment.