Revision: 6511
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6511&view=rev
Author: jdh2358
Date: 2008-12-08 15:30:56 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
added rc param to control legend fancybox
Modified Paths:
--------------
trunk/matplotlib/examples/pylab_examples/legend_demo.py
trunk/matplotlib/examples/pylab_examples/legend_demo3.py
trunk/matplotlib/lib/matplotlib/legend.py
trunk/matplotlib/lib/matplotlib/rcsetup.py
trunk/matplotlib/matplotlibrc.template
Modified: trunk/matplotlib/examples/pylab_examples/legend_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-12-08
15:10:20 UTC (rev 6510)
+++ trunk/matplotlib/examples/pylab_examples/legend_demo.py 2008-12-08
15:30:56 UTC (rev 6511)
@@ -15,7 +15,7 @@
ax = plt.subplot(111)
plt.plot(a,c,'k--',a,d,'k:',a,c+d,'k')
plt.legend(('Model length', 'Data length', 'Total message length'),
- 'upper center', shadow=True)
+ 'upper center', shadow=True, fancybox=True)
plt.ylim([-1,20])
plt.grid(False)
plt.xlabel('Model complexity --->')
Modified: trunk/matplotlib/examples/pylab_examples/legend_demo3.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/legend_demo3.py 2008-12-08
15:10:20 UTC (rev 6510)
+++ trunk/matplotlib/examples/pylab_examples/legend_demo3.py 2008-12-08
15:30:56 UTC (rev 6511)
@@ -1,5 +1,6 @@
#!/usr/bin/env python
-
+import matplotlib
+matplotlib.rcParams['legend.fancybox'] = True
import matplotlib.pyplot as plt
import numpy as np
import pylab
@@ -22,7 +23,7 @@
ax3 = plt.subplot(3,1,3)
myplot(ax3)
-ax3.legend(loc=1, ncol=4, mode="expand", fancybox=False, shadow=True)
+ax3.legend(loc=1, ncol=4, mode="expand", shadow=True)
#title('Damped oscillation')
Modified: trunk/matplotlib/lib/matplotlib/legend.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/legend.py 2008-12-08 15:10:20 UTC (rev
6510)
+++ trunk/matplotlib/lib/matplotlib/legend.py 2008-12-08 15:30:56 UTC (rev
6511)
@@ -63,7 +63,7 @@
loc can be a tuple of the noramilzed coordinate values with
respect its parent.
-
+
Return value is a sequence of text, line instances that make
up the legend
"""
@@ -94,15 +94,15 @@
scatterpoints = 3, # TODO: may be an rcParam
scatteryoffsets=None,
prop = None, # properties for the legend texts
-
+
# the following dimensions are in axes coords
pad = None, # deprecated; use borderpad
- labelsep = None, # deprecated; use labelspacing
- handlelen = None, # deprecated; use handlelength
- handletextsep = None, # deprecated; use handletextpad
+ labelsep = None, # deprecated; use labelspacing
+ handlelen = None, # deprecated; use handlelength
+ handletextsep = None, # deprecated; use handletextpad
axespad = None, # deprecated; use borderaxespad
- # spacing & pad defined as a fractionof the font-size
+ # spacing & pad defined as a fractionof the font-size
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
@@ -113,7 +113,7 @@
ncol=1, # number of columns
mode=None, # mode for horizontal distribution of columns.
None, "expand"
- fancybox=True,
+ fancybox=None, # True use a fancy box, false use a rounded
box, none use rc
shadow = None,
):
"""
@@ -131,7 +131,7 @@
numpoints the number of points in the legend line
prop the font property
markerscale the relative size of legend markers vs. original
- fancybox if True, draw a frame with a round fancybox.
+ fancybox if True, draw a frame with a round fancybox. If
None, use rc
shadow if True, draw a shadow behind legend
scatteryoffsets a list of yoffsets for scatter symbols in legend
@@ -144,7 +144,7 @@
The dimensions of pad and spacing are given as a fraction of the
fontsize. Values from rcParams will be used if None.
-
+
"""
from matplotlib.axes import Axes # local import only to avoid
circularity
from matplotlib.figure import Figure # local import only to avoid
circularity
@@ -172,7 +172,7 @@
# Take care the deprecated keywords
deprecated_kwds = {"pad":"borderpad",
"labelsep":"labelspacing",
- "handlelen":"handlelength",
+ "handlelen":"handlelength",
"handletextsep":"handletextpad",
"axespad":"borderaxespad"}
@@ -182,7 +182,7 @@
# conversion factor
bbox = parent.bbox
axessize_fontsize = min(bbox.width, bbox.height)/self.fontsize
-
+
for k, v in deprecated_kwds.items():
# use deprecated value if not None and if their newer
# counter part is None.
@@ -199,7 +199,7 @@
setattr(self, v, localdict[v])
del localdict
-
+
self._ncol = ncol
if self.numpoints <= 0:
@@ -265,6 +265,9 @@
# The width and height of the legendPatch will be set (in the
# draw()) to the length that includes the padding. Thus we set
# pad=0 here.
+ if fancybox is None:
+ fancybox = rcParams["legend.fancybox"]
+
if fancybox == True:
self.legendPatch.set_boxstyle("round",pad=0,
rounding_size=0.2)
@@ -318,7 +321,7 @@
# find_offset function will be provided to _legend_box and
# _legend_box will draw itself at the location of the return
- # value of the find_offset.
+ # value of the find_offset.
if self._loc == 0:
self._legend_box.set_offset(self._findoffset_best)
else:
@@ -339,7 +342,7 @@
if self.shadow:
shadow = Shadow(self.legendPatch, 2, -2)
shadow.draw(renderer)
-
+
self.legendPatch.draw(renderer)
self._legend_box.draw(renderer)
@@ -360,7 +363,7 @@
Initiallize the legend_box. The legend_box is an instance of
the OffsetBox, which is packed with legend handles and
texts. Once packed, their location is calculated during the
- drawing time.
+ drawing time.
"""
# legend_box is a HPacker, horizontally packed with
@@ -371,7 +374,7 @@
# is an instance of offsetbox.TextArea which contains legend
# text.
-
+
text_list = [] # the list of text instances
handle_list = [] # the list of text instances
@@ -394,12 +397,12 @@
# 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.
# 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.
-
+
# The transformation of each handle will be automatically set
# to self.get_trasnform(). If the artist does not uses its
# default trasnform (eg, Collections), you need to
@@ -413,7 +416,7 @@
if npoints > 1:
# we put some pad here to compensate the size of the
# marker
- xdata = np.linspace(0.3*self.fontsize,
+ xdata = np.linspace(0.3*self.fontsize,
(self.handlelength-0.3)*self.fontsize,
npoints)
xdata_marker = xdata
@@ -484,14 +487,14 @@
size_min]
else:
sizes =
(size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min
-
+
p = type(handle)(handle.get_numsides(),
rotation=handle.get_rotation(),
sizes=sizes,
offsets=zip(xdata_marker,ydata),
transOffset=self.get_transform(),
)
-
+
p.update_from(handle)
p.set_figure(self.figure)
p.set_clip_box(None)
@@ -534,7 +537,7 @@
for h, t in handle_label[i0:i0+di]]
# minimumdescent=False for the text of the last row of the column
itemBoxes[-1].get_children()[1].set_minimumdescent(False)
-
+
# pack columnBox
columnbox.append(VPacker(pad=0,
sep=self.labelspacing*self.fontsize,
@@ -547,7 +550,7 @@
mode = "fixed"
sep = self.columnspacing*self.fontsize
-
+
self._legend_box = HPacker(pad=self.borderpad*self.fontsize,
sep=sep, align="baseline",
mode=mode,
@@ -555,8 +558,8 @@
self.texts = text_list
self.legendHandles = handle_list
-
+
def _auto_legend_data(self):
"""
Returns list of vertices and extents covered by the plot.
@@ -655,12 +658,12 @@
LC:"S",
UC:"N",
C:"C"}
-
+
c = anchor_coefs[loc]
container = parentbbox.padded(-(self.borderaxespad) * self.fontsize)
anchored_box = bbox.anchored(c, container=container)
- return anchored_box.x0, anchored_box.y0
+ return anchored_box.x0, anchored_box.y0
def _find_best_position(self, width, height, consider=None):
Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-12-08 15:10:20 UTC (rev
6510)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py 2008-12-08 15:30:56 UTC (rev
6511)
@@ -417,6 +417,7 @@
'polaraxes.grid' : [True, validate_bool], # display polar grid or
not
#legend properties
+ 'legend.fancybox' : [False,validate_bool],
'legend.loc' : ['upper right',validate_legend_loc], # at some
point, this should be changed to 'best'
'legend.isaxes' : [True,validate_bool], # this option is internally
ignored - it never served any useful purpose
'legend.numpoints' : [2, validate_int], # the number of points in
the legend line
Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template 2008-12-08 15:10:20 UTC (rev
6510)
+++ trunk/matplotlib/matplotlibrc.template 2008-12-08 15:30:56 UTC (rev
6511)
@@ -235,6 +235,8 @@
#grid.linewidth : 0.5 # in points
### Legend
+#legend.fancybox : False # if True, use a rounded box for the
+ # legend, else a rectangle
#legend.isaxes : True
#legend.numpoints : 2 # the number of points in the legend line
#legend.fontsize : large
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins