SF.net SVN: matplotlib:[7047] trunk/matplotlib
Revision: 7047
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7047&view=rev
Author: leejjoon
Date: 2009-04-17 16:34:09 + (Fri, 17 Apr 2009)
Log Message:
---
Added a support for bbox_to_anchor in offsetbox.AnchoredOffsetbox
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/offsetbox.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-04-17 02:31:16 UTC (rev 7046)
+++ trunk/matplotlib/CHANGELOG 2009-04-17 16:34:09 UTC (rev 7047)
@@ -1,5 +1,9 @@
==
+2009-04-17 Added a support for bbox_to_anchor in
+ offsetbox.AnchoredOffsetbox. Improved a documentation.
+ - JJL
+
2009-04-16 Fixed a offsetbox bug that multiline texts are not
correctly aligned. - JJL
Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py
===
--- trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-17 02:31:16 UTC
(rev 7046)
+++ trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-17 16:34:09 UTC
(rev 7047)
@@ -19,7 +19,12 @@
import matplotlib.artist as martist
import matplotlib.text as mtext
import numpy as np
+from matplotlib.transforms import Bbox, TransformedBbox, BboxTransformTo
+from matplotlib.font_manager import FontProperties
+from matplotlib.patches import FancyBboxPatch
+from matplotlib import rcParams
+
from matplotlib.patches import bbox_artist as mbbox_artist
DEBUG=False
# for debuging use
@@ -291,7 +296,7 @@
for c in self.get_visible_children():
if isinstance(c, PackerBase) and c.mode == "expand":
c.set_width(self.width)
-
+
whd_list = [c.get_extent(renderer) for c in
self.get_visible_children()]
whd_list = [(w, h, xd, (h-yd)) for w, h, xd, yd in whd_list]
@@ -752,7 +757,7 @@
self.ref_offset_transform.translate(-ub.x0, -ub.y0)
# restor offset transform
self.offset_transform.matrix_from_values(*_off)
-
+
return ub.width, ub.height, 0., 0.
@@ -767,15 +772,51 @@
bbox_artist(self, renderer, fill=False, props=dict(pad=0.))
-from matplotlib.font_manager import FontProperties
-from matplotlib.patches import FancyBboxPatch
-from matplotlib import rcParams
-from matplotlib.transforms import Bbox
class AnchoredOffsetbox(OffsetBox):
+"""
+An offset box placed according to the legend location
+loc. AnchoredOffsetbox has a single child. When multiple children
+is needed, use other OffsetBox class to enlose them. By default,
+the offset box is anchored against its parent axes. You may
+explicitly specify the bbox_to_anchor.
+"""
+
def __init__(self, loc, pad=0.4, borderpad=0.5,
- child=None, prop=None, frameon=True):
+ child=None, prop=None, frameon=True,
+ bbox_to_anchor=None,
+ bbox_transform=None):
+"""
+loc is a string or an integer specifying the legend location.
+The valid location codes are::
+'upper right' : 1,
+'upper left' : 2,
+'lower left' : 3,
+'lower right' : 4,
+'right': 5,
+'center left' : 6,
+'center right' : 7,
+'lower center' : 8,
+'upper center' : 9,
+'center' : 10,
+
+
+pad : pad around the child for drawing a frame. given in
+ fraction of fontsize.
+
+borderpad : pad between offsetbox frame and the bbox_to_anchor,
+
+child : OffsetBox instance that will be anchored.
+
+prop : font property. This is only used as a reference for paddings.
+
+frameon : draw a frame box if True.
+
+bbox_to_anchor : bbox to anchor. If None, use axes.bbox.
+
+"""
+
super(AnchoredOffsetbox, self).__init__()
self.set_child(child)
@@ -788,7 +829,7 @@
self.prop=FontProperties(size=rcParams["legend.fontsize"])
else:
self.prop = prop
-
+
self.patch = FancyBboxPatch(
xy=(0.0, 0.0), width=1., height=1.,
facecolor='w', edgecolor='k',
@@ -797,48 +838,121 @@
)
self.patch.set_boxstyle("square",pad=0)
self._drawFrame = frameon
+#self._parent_bbox = bbox_to_anchor
+self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
+
+
+
def set_child(self, child):
+"set the child to be anchored"
self._child = child
+def get_child(self):
+"return the child"
+return self._child
+
def get_children(self):
+"return the list of children"
return [self._child]
-def get_child(self):
-return self._child
def get_extent(self, renderer):
+"""
+
SF.net SVN: matplotlib:[7049] trunk/matplotlib/lib
Revision: 7049
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7049&view=rev
Author: leejjoon
Date: 2009-04-17 20:20:07 + (Fri, 17 Apr 2009)
Log Message:
---
removing axes_grid.inset_locator.
Modified Paths:
--
trunk/matplotlib/lib/matplotlib/offsetbox.py
Removed Paths:
-
trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py
Modified: trunk/matplotlib/lib/matplotlib/offsetbox.py
===
--- trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-17 19:35:59 UTC
(rev 7048)
+++ trunk/matplotlib/lib/matplotlib/offsetbox.py2009-04-17 20:20:07 UTC
(rev 7049)
@@ -19,7 +19,7 @@
import matplotlib.artist as martist
import matplotlib.text as mtext
import numpy as np
-from matplotlib.transforms import Bbox, TransformedBbox, BboxTransformTo
+from matplotlib.transforms import Bbox, BboxBase, TransformedBbox,
BboxTransformTo
from matplotlib.font_manager import FontProperties
from matplotlib.patches import FancyBboxPatch
@@ -897,7 +897,7 @@
"""
if bbox is None:
self._bbox_to_anchor = None
-elif isinstance(bbox, Bbox):
+elif isinstance(bbox, BboxBase):
self._bbox_to_anchor = bbox
else:
try:
Deleted: trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py
===
--- trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py
2009-04-17 19:35:59 UTC (rev 7048)
+++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py
2009-04-17 20:20:07 UTC (rev 7049)
@@ -1,191 +0,0 @@
-from matplotlib.offsetbox import AnchoredOffsetbox
-
-
-import matplotlib.transforms as mtrans
-
-class InsetPosition(object):
- def __init__(self, parent, lbwh):
- self.parent = parent
- self.lbwh = lbwh # position of the inset axes in the normalized
coordinate of the parent axes
-
- def __call__(self, ax, renderer):
- bbox_parent = self.parent.get_position(original=False)
- trans = mtrans.BboxTransformTo(bbox_parent)
- bbox_inset = mtrans.Bbox.from_bounds(*self.lbwh)
- bb = mtrans.TransformedBbox(bbox_inset, trans)
- return bb
-
-
-class AnchoredLocatorBase(AnchoredOffsetbox):
- def __init__(self, parent_bbox, offsetbox, loc, **kwargs):
-
- for k in ["parent_bbox", "child", "pad"]:
- if kwargs.has_key(k):
- raise ValueError("%s paramter should not be provided" % (k,))
-
- kwargs["pad"] = 0.
- kwargs["child"] = None
- kwargs["parent_bbox"] = parent_bbox
-
- super(AnchoredLocatorBase, self).__init__(loc, **kwargs)
-
-
- def draw(self, renderer):
- raise RuntimeError("No draw method should be called")
-
-
- def __call__(self, ax, renderer):
-
- fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
- self._update_offset_func(renderer, fontsize)
-
- width, height, xdescent, ydescent = self.get_extent(renderer)
-
- px, py = self.get_offset(width, height, 0, 0)
- bbox_canvas = mtrans.Bbox.from_bounds(px, py, width, height)
- tr = ax.figure.transFigure.inverted()
- bb = mtrans.TransformedBbox(bbox_canvas, tr)
-
- return bb
-
-
-class AnchoredOffsetBoxLocator(AnchoredLocatorBase):
- def __init__(self, parent_bbox, offsetbox, loc, **kwargs):
-
- for k in ["parent_bbox", "child", "pad"]:
- if kwargs.has_key(k):
- raise ValueError("%s paramter should not be provided" % (k,))
-
- kwargs["pad"] = 0.
- kwargs["child"] = offsetbox
- kwargs["parent_bbox"] = parent_bbox
-
- super(AnchoredOffsetBoxLocator, self).__init__(loc, **kwargs)
-
-
-
-from mpl_toolkits.axes_grid.axes_divider import Size
-
-class AnchoredSizeLocator(AnchoredLocatorBase):
- def __init__(self, parent_bbox, x_size, y_size,
- loc, **kwargs):
-
- self.axes = None
- self.x_size = Size.from_any(x_size)
- self.y_size = Size.from_any(y_size)
-
- super(AnchoredSizeLocator, self).__init__(parent_bbox, None, loc,
**kwargs)
-
- def get_extent(self, renderer):
-
- x, y, w, h = self._parent_bbox.bounds
-
- dpi = renderer.points_to_pixels(72.)
-
- r, a = self.x_size.get_size(renderer)
- width = w*r + a*dpi
-
- r, a = self.y_size.get_size(renderer)
- height = h*r + a*dpi
- xd, yd = 0, 0
-
- fontsize = renderer.points_to_pixels(self.prop.get_size_in_points())
- pad = self.pad * fontsize
-
- return width+2*pad, height+2*pad, xd+pad, yd+pad
-
-
- def __call__(self, ax, renderer):
-
- self.axes = ax
- return super(AnchoredSizeLocator, self).__call__(ax, renderer)
-
-
-class AnchoredZoomLocator(AnchoredLocatorBase):
- def __init__(self, parent_axes, zoom,
- loc, **kwargs):
-
- self.parent_axes = parent_axes
- self.zoom = zoom
-
- super(
SF.net SVN: matplotlib:[7050] trunk/matplotlib
Revision: 7050
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7050&view=rev
Author: jdh2358
Date: 2009-04-17 20:40:29 + (Fri, 17 Apr 2009)
Log Message:
---
use 0 for default in rec join outer join if no default given
Modified Paths:
--
trunk/matplotlib/doc/sphinxext/gen_gallery.py
trunk/matplotlib/examples/misc/rec_join_demo.py
trunk/matplotlib/lib/matplotlib/backend_bases.py
trunk/matplotlib/lib/matplotlib/mlab.py
Modified: trunk/matplotlib/doc/sphinxext/gen_gallery.py
===
--- trunk/matplotlib/doc/sphinxext/gen_gallery.py 2009-04-17 20:20:07 UTC
(rev 7049)
+++ trunk/matplotlib/doc/sphinxext/gen_gallery.py 2009-04-17 20:40:29 UTC
(rev 7050)
@@ -38,7 +38,7 @@
print
print "generating gallery: ",
data = []
-for subdir in ('api', 'pylab_examples', 'widgets'):
+for subdir in ('api', 'pylab_examples', 'widgets', 'mplot3d'):
origdir = os.path.join('build', rootdir, subdir)
thumbdir = os.path.join(outdir, rootdir, subdir, 'thumbnails')
if not os.path.exists(thumbdir):
Modified: trunk/matplotlib/examples/misc/rec_join_demo.py
===
--- trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:20:07 UTC
(rev 7049)
+++ trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:40:29 UTC
(rev 7050)
@@ -6,8 +6,8 @@
r.sort()
r1 = r[-10:]
-# Create a new array
-r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float),
+# Create a new array
+r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float),
('marker', np.float)])
r2 = r2.view(np.recarray)
r2.date = r.date[-17:-5]
@@ -19,9 +19,9 @@
print "r2:"
print mlab.rec2txt(r2)
-defaults = {'marker':-1, 'close':np.NaN, 'low':-.}
+defaults = {'marker':-1, '_close':np.NaN, 'low':-.}
for s in ('inner', 'outer', 'leftouter'):
-rec = mlab.rec_join(['date', 'high'], r1, r2,
-jointype=s, defaults=defaults)
+rec = mlab.rec_join(['date', 'high'], r1, r2,
+jointype=s, defaults=defaults)
print "\n%sjoin :\n%s" % (s, mlab.rec2txt(rec))
Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===
--- trunk/matplotlib/lib/matplotlib/backend_bases.py2009-04-17 20:20:07 UTC
(rev 7049)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py2009-04-17 20:40:29 UTC
(rev 7050)
@@ -1058,7 +1058,7 @@
under = self.figure.hitlist(ev)
enter = [a for a in under if a not in self._active]
leave = [a for a in self._active if a not in under]
-print "within:"," ".join([str(x) for x in under])
+#print "within:"," ".join([str(x) for x in under])
#print "entering:",[str(a) for a in enter]
#print "leaving:",[str(a) for a in leave]
# On leave restore the captured colour
@@ -1520,6 +1520,10 @@
- 'pick_event'
- 'resize_event'
- 'scroll_event'
+- 'figure_enter_event',
+- 'figure_leave_event',
+- 'axes_enter_event',
+- 'axes_leave_event'
For the location events (button and key press/release), if the
mouse is over the axes, the variable ``event.inaxes`` will be
Modified: trunk/matplotlib/lib/matplotlib/mlab.py
===
--- trunk/matplotlib/lib/matplotlib/mlab.py 2009-04-17 20:20:07 UTC (rev
7049)
+++ trunk/matplotlib/lib/matplotlib/mlab.py 2009-04-17 20:40:29 UTC (rev
7050)
@@ -2303,6 +2303,17 @@
newrec = np.empty(common_len + left_len + right_len, dtype=newdtype)
+if defaults is not None:
+for thiskey in defaults:
+if thiskey not in newdtype.names:
+warnings.warn('rec_join defaults key="%s" not in new dtype
names "%s"'%(
+thiskey, newdtype.names))
+
+for name in newdtype.names:
+dt = newdtype[name]
+if dt.kind in ('f', 'i'):
+newrec[name] = 0
+
if jointype != 'inner' and defaults is not None: # fill in the defaults
enmasse
newrec_fields = newrec.dtype.fields.keys()
for k, v in defaults.items():
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net
SF.net SVN: matplotlib:[7051] trunk/matplotlib/examples/misc/rec_join_demo. py
Revision: 7051
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7051&view=rev
Author: jdh2358
Date: 2009-04-17 20:40:58 + (Fri, 17 Apr 2009)
Log Message:
---
use 0 for default in rec join outer join if no default given
Modified Paths:
--
trunk/matplotlib/examples/misc/rec_join_demo.py
Modified: trunk/matplotlib/examples/misc/rec_join_demo.py
===
--- trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:40:29 UTC
(rev 7050)
+++ trunk/matplotlib/examples/misc/rec_join_demo.py 2009-04-17 20:40:58 UTC
(rev 7051)
@@ -19,7 +19,7 @@
print "r2:"
print mlab.rec2txt(r2)
-defaults = {'marker':-1, '_close':np.NaN, 'low':-.}
+defaults = {'marker':-1, 'close':np.NaN, 'low':-.}
for s in ('inner', 'outer', 'leftouter'):
rec = mlab.rec_join(['date', 'high'], r1, r2,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
--
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
