Revision: 4011
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4011&view=rev
Author: mdboom
Date: 2007-10-26 08:58:50 -0700 (Fri, 26 Oct 2007)
Log Message:
-----------
More coverage. Add draw_path_collection to SVG.
Modified Paths:
--------------
branches/transforms/examples/backend_driver.py
branches/transforms/examples/legend_auto.py
branches/transforms/lib/matplotlib/axis.py
branches/transforms/lib/matplotlib/backends/backend_ps.py
branches/transforms/lib/matplotlib/backends/backend_svg.py
branches/transforms/lib/matplotlib/figure.py
branches/transforms/lib/matplotlib/quiver.py
branches/transforms/lib/matplotlib/scale.py
branches/transforms/lib/matplotlib/transforms.py
Modified: branches/transforms/examples/backend_driver.py
===================================================================
--- branches/transforms/examples/backend_driver.py 2007-10-26 03:40:33 UTC
(rev 4010)
+++ branches/transforms/examples/backend_driver.py 2007-10-26 15:58:50 UTC
(rev 4011)
@@ -55,6 +55,7 @@
'image_origin.py',
'invert_axes.py',
'layer_images.py',
+ 'legend_auto.py',
'legend_demo.py',
'legend_demo2.py',
'line_collection.py',
Modified: branches/transforms/examples/legend_auto.py
===================================================================
--- branches/transforms/examples/legend_auto.py 2007-10-26 03:40:33 UTC (rev
4010)
+++ branches/transforms/examples/legend_auto.py 2007-10-26 15:58:50 UTC (rev
4011)
@@ -79,7 +79,12 @@
if __name__ == '__main__':
nfigs = 10
- figures = [int(f) for f in sys.argv[1:]]
+ figures = []
+ for f in sys.argv[1:]:
+ try:
+ figures.append(int(f))
+ except ValueError:
+ pass
if len(figures) == 0:
figures = range(1, nfigs+1)
Modified: branches/transforms/lib/matplotlib/axis.py
===================================================================
--- branches/transforms/lib/matplotlib/axis.py 2007-10-26 03:40:33 UTC (rev
4010)
+++ branches/transforms/lib/matplotlib/axis.py 2007-10-26 15:58:50 UTC (rev
4011)
@@ -18,7 +18,7 @@
from font_manager import FontProperties
from text import Text, TextWithDash, _process_text_args
from transforms import Affine2D, Bbox, blended_transform_factory,
interval_contains, \
- interval_contains_open, IntervalTransform, IdentityTransform
+ interval_contains_open, IdentityTransform
from patches import bbox_artist
from scale import scale_factory
Modified: branches/transforms/lib/matplotlib/backends/backend_ps.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_ps.py 2007-10-26
03:40:33 UTC (rev 4010)
+++ branches/transforms/lib/matplotlib/backends/backend_ps.py 2007-10-26
15:58:50 UTC (rev 4011)
@@ -505,12 +505,13 @@
path_codes = []
for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
master_transform, paths, all_transforms)):
- ps_cmd = ['/p%x_%x {' % (self._path_collection_id, i),
+ name = 'p%x_%x' % (self._path_collection_id, i)
+ ps_cmd = ['/%s {' % name,
'newpath', 'translate']
ps_cmd.append(self._convert_path(path, transform))
ps_cmd.extend(['} bind def\n'])
write('\n'.join(ps_cmd))
- path_codes.append("p%x_%x" % (self._path_collection_id, i))
+ path_codes.append(name)
for xo, yo, path_id, gc, rgbFace in self._iter_collection(
path_codes, cliprect, clippath, clippath_trans,
Modified: branches/transforms/lib/matplotlib/backends/backend_svg.py
===================================================================
--- branches/transforms/lib/matplotlib/backends/backend_svg.py 2007-10-26
03:40:33 UTC (rev 4010)
+++ branches/transforms/lib/matplotlib/backends/backend_svg.py 2007-10-26
15:58:50 UTC (rev 4011)
@@ -42,6 +42,7 @@
self._clipd = {}
self._char_defs = {}
self._markers = {}
+ self._path_collection_id = 0
self.mathtext_parser = MathTextParser('SVG')
self.fontd = {}
svgwriter.write(svgProlog%(width,height,width,height))
@@ -192,7 +193,33 @@
for x, y in tpath.vertices:
details = 'xlink:href="#%s" x="%f" y="%f"' % (name, x, y)
self._draw_svg_element('use', details, gc, rgbFace)
+
+ def draw_path_collection(self, master_transform, cliprect, clippath,
+ clippath_trans, paths, all_transforms, offsets,
+ offsetTrans, facecolors, edgecolors, linewidths,
+ linestyles, antialiaseds):
+ write = self._svgwriter.write
+
+ path_codes = []
+ write('<defs>\n')
+ for i, (path, transform) in enumerate(self._iter_collection_raw_paths(
+ master_transform, paths, all_transforms)):
+ name = 'coll%x_%x' % (self._path_collection_id, i)
+ transform = transform.frozen().scale(1.0, -1.0)
+ d = self._convert_path(path, transform)
+ write('<path id="%s" d="%s"/>\n' % (name, d))
+ path_codes.append(name)
+ write('</defs>\n')
+ for xo, yo, path_id, gc, rgbFace in self._iter_collection(
+ path_codes, cliprect, clippath, clippath_trans,
+ offsets, offsetTrans, facecolors, edgecolors,
+ linewidths, linestyles, antialiaseds):
+ details = 'xlink:href="#%s" x="%f" y="%f"' % (path_id, xo,
self.height - yo)
+ self._draw_svg_element('use', details, gc, rgbFace)
+
+ self._path_collection_id += 1
+
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
# MGDTODO: Support clippath here
trans = [1,0,0,1,0,0]
Modified: branches/transforms/lib/matplotlib/figure.py
===================================================================
--- branches/transforms/lib/matplotlib/figure.py 2007-10-26 03:40:33 UTC
(rev 4010)
+++ branches/transforms/lib/matplotlib/figure.py 2007-10-26 15:58:50 UTC
(rev 4011)
@@ -328,7 +328,7 @@
w,h = args
dpival = self.dpi
- self.bbox_inches.max = w, h
+ self.bbox_inches.p1 = w, h
if forward:
dpival = self.dpi
@@ -339,7 +339,7 @@
manager.resize(int(canvasw), int(canvash))
def get_size_inches(self):
- return self.bbox_inches.max
+ return self.bbox_inches.p1
def get_edgecolor(self):
'Get the edge color of the Figure rectangle'
Modified: branches/transforms/lib/matplotlib/quiver.py
===================================================================
--- branches/transforms/lib/matplotlib/quiver.py 2007-10-26 03:40:33 UTC
(rev 4010)
+++ branches/transforms/lib/matplotlib/quiver.py 2007-10-26 15:58:50 UTC
(rev 4011)
@@ -238,8 +238,8 @@
self.set_transform(self.Q.ax.figure.transFigure)
elif self.coord == 'inches':
dx = ax.figure.dpi
- bb = transforms.Bbox(transforms.origin(), transforms.Point(dx, dx))
- trans = transforms.get_bbox_transform(transforms.unit_bbox(), bb)
+ bb = transforms.Bbox.from_extents(0, 0, dx, dy)
+ trans = transforms.BboxTransform(Bbox.unit(), bb)
self.set_transform(trans)
else:
raise ValueError('unrecognized coordinates')
Modified: branches/transforms/lib/matplotlib/scale.py
===================================================================
--- branches/transforms/lib/matplotlib/scale.py 2007-10-26 03:40:33 UTC (rev
4010)
+++ branches/transforms/lib/matplotlib/scale.py 2007-10-26 15:58:50 UTC (rev
4011)
@@ -6,8 +6,7 @@
LogFormatter, LogFormatterMathtext
from ticker import NullLocator, FixedLocator, LinearLocator, LogLocator, \
AutoLocator
-from transforms import Affine1DBase, IntervalTransform, Transform, \
- composite_transform_factory, IdentityTransform
+from transforms import Transform, composite_transform_factory,
IdentityTransform
class ScaleBase(object):
def set_default_locators_and_formatters(self, axis):
Modified: branches/transforms/lib/matplotlib/transforms.py
===================================================================
--- branches/transforms/lib/matplotlib/transforms.py 2007-10-26 03:40:33 UTC
(rev 4010)
+++ branches/transforms/lib/matplotlib/transforms.py 2007-10-26 15:58:50 UTC
(rev 4011)
@@ -128,62 +128,63 @@
might normally be used.
"""
return self
-
- def write_graphviz(self, fobj, highlight=[]):
- """
- For debugging purposes.
- Writes the transform tree rooted at 'self' to a graphviz "dot"
- format file. This file can be run through the "dot" utility
- to produce a graph of the transform tree.
+ if DEBUG:
+ def write_graphviz(self, fobj, highlight=[]):
+ """
+ For debugging purposes.
- Affine transforms are marked in blue. Bounding boxes are
- marked in yellow.
+ Writes the transform tree rooted at 'self' to a graphviz "dot"
+ format file. This file can be run through the "dot" utility
+ to produce a graph of the transform tree.
- fobj: A Python file-like object
- """
- if not DEBUG:
- return
-
- seen = cbook.set()
+ Affine transforms are marked in blue. Bounding boxes are
+ marked in yellow.
- def recurse(root):
- if root in seen:
- return
- seen.add(root)
- props = {}
- label = root.__class__.__name__
- if root._invalid:
- label = '[%s]' % label
- if root in highlight:
- props['style'] = 'bold'
- if root.is_affine:
- props['shape'] = 'parallelogram'
- if root.is_bbox:
- props['shape'] = 'box'
- props['label'] = '"%s"' % label
- props = ' '.join(['%s=%s' % (key, val) for key, val in
props.items()])
+ fobj: A Python file-like object
+ """
+ seen = cbook.set()
- fobj.write('%s [%s];\n' %
- (hash(root), props))
+ def recurse(root):
+ if root in seen:
+ return
+ seen.add(root)
+ props = {}
+ label = root.__class__.__name__
+ if root._invalid:
+ label = '[%s]' % label
+ if root in highlight:
+ props['style'] = 'bold'
+ if root.is_affine:
+ props['shape'] = 'parallelogram'
+ if root.is_bbox:
+ props['shape'] = 'box'
+ props['label'] = '"%s"' % label
+ props = ' '.join(['%s=%s' % (key, val) for key, val in
props.items()])
- for child in root._children:
- name = '?'
- for key, val in root.__dict__.items():
- if val is child:
- name = key
- break
- fobj.write('%s -> %s [label="%s", fontsize=10];\n' % (
- hash(root),
- hash(child),
- name))
- recurse(child)
+ fobj.write('%s [%s];\n' %
+ (hash(root), props))
- fobj.write("digraph G {\n")
- recurse(self)
- fobj.write("}\n")
+ for child in root._children:
+ name = '?'
+ for key, val in root.__dict__.items():
+ if val is child:
+ name = key
+ break
+ fobj.write('%s -> %s [label="%s", fontsize=10];\n' % (
+ hash(root),
+ hash(child),
+ name))
+ recurse(child)
+
+ fobj.write("digraph G {\n")
+ recurse(self)
+ fobj.write("}\n")
+ else:
+ def write_graphviz(self, fobj, highlight=[]):
+ return
+
-
class BboxBase(TransformNode):
"""
This is the base class of all bounding boxes, and provides
@@ -226,6 +227,14 @@
return self.get_points()[1, 1]
y1 = property(_get_y1)
+ def _get_p0(self):
+ return self.get_points()[0]
+ p0 = property(_get_p0)
+
+ def _get_p1(self):
+ return self.get_points()[1]
+ p1 = property(_get_p1)
+
def _get_xmin(self):
return min(self.get_points()[:, 0])
xmin = property(_get_xmin)
@@ -737,15 +746,15 @@
self.invalidate()
y1 = property(BboxBase._get_y1, _set_y1)
- def _set_min(self, val):
+ def _set_p0(self, val):
self._points[0] = val
self.invalidate()
- min = property(BboxBase._get_min, _set_min)
-
- def _set_max(self, val):
+ p0 = property(BboxBase._get_p0, _set_p0)
+
+ def _set_p1(self, val):
self._points[1] = val
self.invalidate()
- max = property(BboxBase._get_max, _set_max)
+ p1 = property(BboxBase._get_p1, _set_p1)
def _set_intervalx(self, interval):
self._points[:, 0] = interval
@@ -1137,240 +1146,6 @@
get_affine.__doc__ = Transform.get_affine.__doc__
-class Affine1DBase(AffineBase):
- """
- The base class of all 1D affine transforms.
-
- Provides the read-only interface.
-
- 1D affine transformations are performed using a 2x2 numpy array:
-
- a b
- 0 1
-
- where a is scale and b is translation.
- """
- input_dims = 1
- output_dims = 1
- is_separable = True
-
- def __init__(self):
- AffineBase.__init__(self)
-
- def frozen(self):
- return Affine1D(self.get_matrix().copy())
- frozen.__doc__ = AffineBase.frozen.__doc__
-
- def __array__(self, *args, **kwargs):
- return self.get_matrix()
-
- def to_values(self):
- """
- Returns a, b
- """
- mtx = self.get_matrix()
- return mtx[0]
-
- [EMAIL PROTECTED]
- def matrix_from_values(a, b):
- """
- Create a new transformation matrix as a numpy array using the
- values a, b, where:
-
- a: scale
- b: translation
- """
- return npy.array([[a, b], [0.0, 1.0]], npy.float_)
- matrix_from_values = staticmethod(matrix_from_values)
-
- def transform(self, values):
- mtx = self.get_matrix()
- points = npy.asarray(values, npy.float_)
- return points * mtx[0, 0] + mtx[0, 1]
-
- if DEBUG:
- _transform = transform
- def transform(self, values):
- # The major speed trap here is just converting to the points
- # to an array in the first place. If we can use more arrays
- # upstream, that should help here.
- if not isinstance(values, npy.ndarray):
- warnings.warn(
- ('A non-numpy array of type %s was passed in for ' +
- 'transformation. Please correct this.')
- % type(values))
- return self._transform(values)
- transform.__doc__ = AffineBase.transform.__doc__
-
- transform_affine = transform
- transform_affine.__doc__ = AffineBase.transform_affine.__doc__
-
- def inverted(self):
- if self._inverted is None or self._invalid:
- mtx = self.get_matrix()
- self._inverted = Affine1D(inv(mtx))
- self._invalid = 0
- return self._inverted
- inverted.__doc__ = AffineBase.inverted.__doc__
-
-
-class Affine1D(Affine1DBase):
- """
- A concrete 1D affine transformation.
-
- 1D affine transformations are performed using a 2x2 numpy array:
-
- a b
- 0 1
-
- where a is scale and b is translation.
- """
- def __init__(self, matrix = None):
- """
- Initialize an Affine transform from a 2x2 numpy float array.
-
- If matrix is None, initialize with the identity transform.
- """
- Affine1DBase.__init__(self)
- if matrix is None:
- matrix = npy.identity(2)
- else:
- matrix = npy.asarray(matrix, npy.float_)
- assert matrix.shape == (2, 2)
- self._mtx = matrix
- self._invalid = 0
-
- def __repr__(self):
- return "Affine1D(%s)" % repr(self._mtx)
- __str__ = __repr__
-
- def __cmp__(self, other):
- if (isinstance(other, Affine1D) and
- (self.get_matrix() == other.get_matrix()).all()):
- return 0
- return -1
-
- [EMAIL PROTECTED]
- def from_values(a, b):
- """
- Create a new Affine1D instance from the given values.
-
- a: scale
- b: translation
- """
- return Affine1D(Affine1D.matrix_from_values(a, b))
- from_values = staticmethod(from_values)
-
- def get_matrix(self):
- """
- Get the underlying transformation matrix as a 2x2 numpy array.
-
- a b
- 0 1
-
- where a is scale and b is translation.
- """
- self._invalid = 0
- return self._mtx
-
- def set_matrix(self, mtx):
- """
- Set the underlying transformation matrix from a 2x2 numpy array.
-
- a b
- 0 1
-
- where a is scale and b is translation.
- """
- self._mtx = mtx
- self.invalidate()
-
- def set(self, other):
- """
- Set this transformation from a frozen copy of another
- Affine1DBase instance.
- """
- assert isinstance(other, Affine1DBase)
- self._mtx = other.get_matrix()
- self.invalidate()
-
- [EMAIL PROTECTED]
- def identity():
- """
- Return a new Affine1D instance that is the identity transform.
-
- Unless this transform will be mutated later on, consider using
- the faster IdentityTransform class instead.
- """
- return Affine1D(npy.identity(2))
- identity = staticmethod(identity)
-
- def clear(self):
- """
- Resets this transformation back to the identity transform.
- """
- self._mtx = npy.identity(2)
- self.invalidate()
- return self
-
- def translate(self, t):
- """
- Add a translation t to this transform.
-
- Returns self, so this method can easily be chained with more
- calls to translate() and scale().
- """
- self._mtx[0, 1] += t
- self.invalidate()
- return self
-
- def scale(self, s):
- """
- Add a scale s to this transform.
-
- Returns self, so this method can easily be chained with more
- calls to translate() and scale().
- """
- self._mtx[0, 0] *= s
- self.invalidate()
- return self
-
-
-class IntervalTransform(Affine1DBase):
- """
- A 1D transformation that linearly transforms points along the
- input interval (0.0, 1.0) to an arbitrary child interval.
- """
- def __init__(self, bbox, direction):
- """
- bbox: A Bbox instance containing the child interval.
- direction: A string 'x' or 'y' indicating the interval of the
- bbox to use as the child interval.
- """
- assert direction in ('x', 'y')
- assert bbox.is_bbox
-
- Affine1DBase.__init__(self)
- self._bbox = bbox
- self._direction = "interval" + direction
- self.set_children(bbox)
- self._mtx = None
-
- def __repr__(self):
- return "IntervalTransform(%s)" % (getattr(self._bbox, self._direction))
- __str__ = __repr__
-
- def get_matrix(self):
- if self._invalid:
- vmin, vmax = getattr(self._bbox, self._direction)
- self._mtx = inv(npy.array([[vmax - vmin, vmin],
- [0.0, 1.0]], npy.float_))
- self._inverted = None
- self._invalid = 0
- return self._mtx
- get_matrix.__doc__ = Affine1DBase.get_matrix.__doc__
-
-
class Affine2DBase(AffineBase):
"""
The base class of all 2D affine transformations.
@@ -1780,58 +1555,8 @@
self._invalid = 0
return self._affine
get_affine.__doc__ = Transform.get_affine.__doc__
-
-
-class BlendedAffine1D(Affine2DBase):
- """
- A "blended" transform uses one transform for the x-direction, and
- another transform for the y-direction.
-
- This version is an optimization for the case where both child
- transforms are of type Affine1DBase.
- """
- is_separable = True
- def __init__(self, x_transform, y_transform):
- """
- Create a new "blended" transform using x_transform to
- transform the x-axis and y_transform to transform the y_axis.
-
- Both x_transform and y_transform must be 1D affine transforms.
-
- You will generally not call this constructor directly but use
- the blended_transform_factory function instead, which can
- determine automatically which kind of blended transform to
- create.
- """
- assert isinstance(x_transform, Affine1DBase)
- assert isinstance(y_transform, Affine1DBase)
-
- Transform.__init__(self)
- self._x = x_transform
- self._y = y_transform
- self.set_children(x_transform, y_transform)
-
- Affine2DBase.__init__(self)
- self._mtx = None
-
- def __repr__(self):
- return "BlendedAffine1D(%s,%s)" % (self._x, self._y)
- __str__ = __repr__
-
- def get_matrix(self):
- if self._invalid:
- x_mtx = self._x.get_matrix()
- y_mtx = self._y.get_matrix()
- self._mtx = npy.array([[x_mtx[0, 0], 0.0, x_mtx[0, 1]],
- [0.0, y_mtx[0, 0], y_mtx[0, 1]],
- [0.0, 0.0, 1.0]])
- self._inverted = None
- self._invalid = 0
- return self._mtx
- get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
-
class BlendedAffine2D(Affine2DBase):
"""
A "blended" transform uses one transform for the x-direction, and
@@ -1900,9 +1625,6 @@
if (isinstance(x_transform, Affine2DBase)
and isinstance(y_transform, Affine2DBase)):
return BlendedAffine2D(x_transform, y_transform)
- elif (isinstance(x_transform, Affine1DBase)
- and isinstance(y_transform, Affine1DBase)):
- return BlendedAffine1D(x_transform, y_transform)
return BlendedGenericTransform(x_transform, y_transform)
@@ -2235,7 +1957,7 @@
bbox_copy = copy.deepcopy(bbox)
assert (bbox.extents == bbox_copy.extents).all()
- bbox_copy.max = (14, 15)
+ bbox_copy.p1 = (14, 15)
assert bbox.bounds == (10, 11, 12, 13)
assert bbox_copy.bounds == (10, 11, 4, 4)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins