268 lines (265 with data), 26.7 kB
@header@
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="matplotlib.html"><font color="#ffffff">matplotlib</font></a>.transforms</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/lib/python2.4/site-packages/matplotlib/transforms.py">/usr/lib/python2.4/site-packages/matplotlib/transforms.py</a></font></td></tr></table>
<p><tt>The transforms module is broken into two parts, a collection of<br>
classes written in the extension module _transforms to handle<br>
efficient transformation of data, and some helper functions in<br>
transforms to make it easy to instantiate and use those objects.<br>
Hence the core of this module lives in _transforms.<br>
<br>
The transforms class is built around the idea of a LazyValue. A<br>
LazyValue is a base class that defines a method get that returns the<br>
value. The concrete derived class Value wraps a float, and simply<br>
returns the value of that float. The concrete derived class BinOp<br>
allows binary operations on LazyValues, so you can add them, multiply<br>
them, etc. When you do something like<br>
<br>
inches = <a href="#-Value">Value</a>(8)<br>
dpi = <a href="#-Value">Value</a>(72)<br>
width = inches * dpi<br>
<br>
width is a BinOp instance (that tells you the width of the figure in<br>
pixels. Later, if the figure size in changed, ie we call<br>
<br>
inches.set(10)<br>
<br>
The width variable is automatically updated because it stores a<br>
pointer to the inches variable, not the value. Since a BinOp is also<br>
a lazy value, you can define binary operations on BinOps as well, such<br>
as<br>
<br>
middle = <a href="#-Value">Value</a>(0.5) * width<br>
<br>
The bounding box class Bbox is also heavily used, and is defined by a<br>
lower left point ll and an upper right point ur. The points ll and ur<br>
are given by <a href="#-Point">Point</a>(x, y) instances, where x and y are LazyValues. So<br>
you can represent a point such as <br>
<br>
ll = <a href="#-Point">Point</a>( <a href="#-Value">Value</a>(0), <a href="#-Value">Value</a>(0) ) # the origin<br>
ur = <a href="#-Point">Point</a>( width, height ) # the upper right of the figure<br>
<br>
where width and height are defined as above, using the product of the<br>
figure width in inches and the dpi. This is, in face, how the Figure<br>
bbox is defined<br>
<br>
bbox = <a href="#-Bbox">Bbox</a>(ll, ur)<br>
<br>
A bbox basically defines an x,y coordinate system, with ll giving the<br>
lower left of the coordinate system and ur giving the upper right.<br>
<br>
The bbox methods are<br>
<br>
ll() - return the lower left Point<br>
ur() - return the upper right Point<br>
contains(x,y) - return True if self contains point<br>
overlaps(bbox) - return True if self overlaps bbox<br>
overlapsx(bbox) - return True if self overlaps bbox in the x interval<br>
overlapsy(bbox) - return True if self overlaps bbox in the y interval<br>
intervalx() - return the x Interval instance<br>
intervaly() - return the y interval instance<br>
get_bounds() - get the left, bottom, width, height bounding tuple<br>
update(xys, ignore) - update the bbox to bound all the xy tuples in<br>
xys; if ignore is true ignore the current contents of bbox and<br>
just bound the tuples. If ignore is false, bound self + tuples<br>
width() - return the width of the bbox<br>
height() - return the height of the bbox<br>
xmax() - return the x coord of upper right<br>
ymax() - return the y coord of upper right<br>
xmin() - return the x coord of lower left<br>
ymin() - return the y coord of lower left<br>
scale(sx,sy) - scale the bbox by sx, sy<br>
deepcopy() - return a deep copy of self (pointers are lost)<br>
<br>
<br>
The basic transformation maps one bbox to another, with an optional<br>
nonlinear transformation of one of coordinates (eg log scaling).<br>
<br>
The base class for transformations is Transformation, and the concrete<br>
derived classes are SeparableTransformation and Affine. Earlier<br>
versions of matplotlib handled transformation of x and y separately<br>
(ie we assumed all transformations were separable) but this makes it<br>
difficult to do rotations or polar transformations, for example. All<br>
artists contain their own transformation, defaulting to the identity<br>
transform.<br>
<br>
The signature of a separable transformation instance is<br>
<br>
trans = <a href="#-SeparableTransformation">SeparableTransformation</a>(bbox1, bbox2, funcx, funcy)<br>
<br>
where funcx and funcy operate on x and y. The typical linear<br>
coordinate transformation maps one bounding box to another, with funcx<br>
and funcy both identity. Eg,<br>
<br>
transData = Transformation(viewLim, displayLim,<br>
<a href="#-Func">Func</a>(IDENTITY), <a href="#-Func">Func</a>(IDENTITY))<br>
<br>
maps the axes view limits to display limits. If the xaxis scaling is<br>
changed to log, one simply calls<br>
<br>
transData.get_funcx.set_type(LOG10)<br>
<br>
For more general transformations including rotation, the Affine class<br>
is provided, which is constructed with 6 LazyValue instances:<br>
a, b, c, d, tx, ty. These give the values of the matrix transformation<br>
<br>
[xo = |a c| [xi + [tx <br>
yo] |b d| yi] ty]<br>
<br>
where if sx, sy are the scaling components, tx, y are the translation<br>
components, and alpha is the rotation<br>
<br>
a = sx*cos(alpha);<br>
b = -sx*sin(alpha);<br>
c = sy*sin(alpha);<br>
d = sy*cos(alpha);<br>
<br>
From a user perspective, the most important Tranformation methods are<br>
<br>
All transformations<br>
-------------------<br>
freeze() - eval and freeze the lazy objects<br>
thaw() - release the lazy objects<br>
<br>
xy_tup(xy) - transform the tuple (x,y)<br>
seq_x_y(x, y) - transform the python sequences x and y<br>
numerix_x_y(x, y) - x and y are numerix 1D arrays<br>
seq_xy_tups(seq) - seq is a sequence of xy tuples<br>
inverse_xy_tup(xy) - apply the inverse transformation to tuple xy <br>
<br>
set_offset(xy, trans) - xy is an x,y tuple and trans is a<br>
Transformation instance. This will apply a post transformational<br>
offset of all future transformations by xt,yt = trans.xy_tup(xy[0], xy[1])<br>
<br>
<br>
Separable transformations<br>
-------------------------<br>
<br>
get_bbox1() - return the input bbox<br>
get_bbox2() - return the output bbox<br>
set_bbox1() - set the input bbox<br>
set_bbox2() - set the output bbox<br>
get_funcx() - return the Func instance on x<br>
get_funcy() - return the Func instance on y<br>
set_funcx() - set the Func instance on x<br>
set_funcy() - set the Func instance on y<br>
<br>
Affine transformations<br>
----------------------<br>
<br>
as_vec6() - return the affine as length 6 list of Values<br>
<br>
<br>
In general, you shouldn't need to construct your own transformations,<br>
but should use the helper functions defined in this module.<br>
<br>
<br>
zero - return <a href="#-Value">Value</a>(0)<br>
one - return <a href="#-Value">Value</a>(1)<br>
origin - return <a href="#-Point">Point</a>(<a href="#-zero">zero</a>(), <a href="#-zero">zero</a>())<br>
unit_bbox - return the 0,0 to 1,1 bounding box<br>
identity_affine - An affine identity transformation<br>
identity_transform - An identity separable transformation<br>
translation_transform - a pure translational affine<br>
scale_transform - a pure scale affine<br>
scale_sep_transform - a pure scale separable transformation<br>
scale_translation_transform - a scale and translate affine<br>
bound_vertices - return the bbox that bounds all the xy tuples<br>
bbox_all - return the bbox that bounds all the bboxes<br>
lbwh_to_bbox - build a bbox from tuple<br>
left, bottom, width, height tuple<br>
<br>
multiply_affines - return the affine that is the matrix product of<br>
the two affines<br>
<br>
get_bbox_transform - return a SeparableTransformation instance that<br>
transforms one bbox to another<br>
<br>
blend_xy_sep_transform - mix the x and y components of two separable<br>
transformations into a new transformation. This allows you to<br>
specify x and y in different coordinate systems<br>
<br>
transform_bbox - apply a transformation to a bbox and return the<br>
transformed bbox<br>
<br>
inverse_transform_bbox - apply the inverse transformation of a bbox<br>
and return the inverse transformed bbox<br>
<br>
<br>
The units/transform_unit.py code has many examples.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="math.html">math</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-Affine"><strong>Affine</strong></a>(...)</dt><dd><tt><a href="#-Affine">Affine</a>(a,b,c,d,tx,ty)</tt></dd></dl>
<dl><dt><a name="-Bbox"><strong>Bbox</strong></a>(...)</dt><dd><tt><a href="#-Bbox">Bbox</a>(ll, ur)</tt></dd></dl>
<dl><dt><a name="-Func"><strong>Func</strong></a>(...)</dt><dd><tt><a href="#-Func">Func</a>(typecode)</tt></dd></dl>
<dl><dt><a name="-FuncXY"><strong>FuncXY</strong></a>(...)</dt><dd><tt><a href="#-FuncXY">FuncXY</a>(funcx, funcy)</tt></dd></dl>
<dl><dt><a name="-Interval"><strong>Interval</strong></a>(...)</dt><dd><tt><a href="#-Interval">Interval</a>(val1, val2)</tt></dd></dl>
<dl><dt><a name="-NonseparableTransformation"><strong>NonseparableTransformation</strong></a>(...)</dt><dd><tt><a href="#-NonseparableTransformation">NonseparableTransformation</a>(box1, box2, funcxy))</tt></dd></dl>
<dl><dt><a name="-Point"><strong>Point</strong></a>(...)</dt><dd><tt><a href="#-Point">Point</a>(x, y)</tt></dd></dl>
<dl><dt><a name="-SeparableTransformation"><strong>SeparableTransformation</strong></a>(...)</dt><dd><tt><a href="#-SeparableTransformation">SeparableTransformation</a>(box1, box2, funcx, funcy))</tt></dd></dl>
<dl><dt><a name="-Value"><strong>Value</strong></a>(...)</dt><dd><tt><a href="#-Value">Value</a>(x)</tt></dd></dl>
<dl><dt><a name="-array"><strong>array</strong></a>(...)</dt><dd><tt><a href="#-array">array</a>(sequence, typecode=None, copy=1, savespace=0) will return a new array formed from the given (potentially nested) sequence with type given by typecode. If no typecode is given, then the type will be determined as the minimum type required to hold the objects in sequence. If copy is zero and sequence is already an array, a reference will be returned. If savespace is nonzero, the new array will maintain its precision in operations.</tt></dd></dl>
<dl><dt><a name="-bbox_all"><strong>bbox_all</strong></a>(bboxes)</dt><dd><tt>Return the Bbox that bounds all bboxes</tt></dd></dl>
<dl><dt><a name="-blend_xy_sep_transform"><strong>blend_xy_sep_transform</strong></a>(trans1, trans2)</dt><dd><tt>If trans1 and trans2 are SeparableTransformation instances, you can<br>
build a new SeparableTransformation from them by extracting the x and y<br>
bounding points and functions and recomposing a new SeparableTransformation<br>
<br>
This function extracts all the relevant bits from trans1 and<br>
trans2 and returns the new Transformation instance. This is<br>
useful, for example, if you want to specify x in data coordinates<br>
and y in axes coordinates.</tt></dd></dl>
<dl><dt><a name="-bound_vertices"><strong>bound_vertices</strong></a>(verts)</dt><dd><tt>Return the Bbox of the sequence of x,y tuples in verts</tt></dd></dl>
<dl><dt><a name="-copy_bbox_transform"><strong>copy_bbox_transform</strong></a>(trans)</dt><dd><tt>return a deep copy of the bbox transform</tt></dd></dl>
<dl><dt><a name="-get_bbox_transform"><strong>get_bbox_transform</strong></a>(boxin, boxout)</dt><dd><tt>return the transform that maps transform one bounding box to<br>
another</tt></dd></dl>
<dl><dt><a name="-get_vec6_rotation"><strong>get_vec6_rotation</strong></a>(v)</dt><dd><tt>v is an affine vec6 a,b,c,d,tx,ty; return rotation in degrees</tt></dd></dl>
<dl><dt><a name="-get_vec6_scales"><strong>get_vec6_scales</strong></a>(v)</dt><dd><tt>v is an affine vec6 a,b,c,d,tx,ty; return sx, sy</tt></dd></dl>
<dl><dt><a name="-identity_affine"><strong>identity_affine</strong></a>()</dt><dd><tt>Get an affine transformation that maps x,y -> x,y</tt></dd></dl>
<dl><dt><a name="-identity_transform"><strong>identity_transform</strong></a>()</dt><dd><tt>Get an affine transformation that maps x,y -> x,y</tt></dd></dl>
<dl><dt><a name="-inverse_transform_bbox"><strong>inverse_transform_bbox</strong></a>(trans, bbox)</dt><dd><tt>inverse transform the bbox</tt></dd></dl>
<dl><dt><a name="-invert_vec6"><strong>invert_vec6</strong></a>(v)</dt><dd><tt>v is a,b,c,d,tx,ty vec6 repr of a matrix<br>
[ a b 0<br>
c d 0<br>
tx ty 1]<br>
<br>
Return the inverse of v as a vec6</tt></dd></dl>
<dl><dt><a name="-lbwh_to_bbox"><strong>lbwh_to_bbox</strong></a>(l, b, w, h)</dt></dl>
<dl><dt><a name="-multiply_affines"><strong>multiply_affines</strong></a>(v1, v2)</dt><dd><tt>v1 and v2 are Affine instances</tt></dd></dl>
<dl><dt><a name="-one"><strong>one</strong></a>()</dt></dl>
<dl><dt><a name="-origin"><strong>origin</strong></a>()</dt></dl>
<dl><dt><a name="-scale_sep_transform"><strong>scale_sep_transform</strong></a>(sx, sy)</dt><dd><tt>Return a pure scale transformation as a SeparableTransformation;<br>
sx and sy are LazyValue instances (Values or binary opertations on<br>
values)</tt></dd></dl>
<dl><dt><a name="-scale_transform"><strong>scale_transform</strong></a>(sx, sy)</dt><dd><tt>Return a pure scale transformation as an Affine instance; sx and<br>
sy are LazyValue instances (Values or binary opertations on<br>
values)</tt></dd></dl>
<dl><dt><a name="-transform_bbox"><strong>transform_bbox</strong></a>(trans, bbox)</dt><dd><tt>transform the bbox to a new bbox</tt></dd></dl>
<dl><dt><a name="-translation_transform"><strong>translation_transform</strong></a>(tx, ty)</dt><dd><tt>return a pure tranlational transformation tx and ty are LazyValue<br>
instances (Values or binary opertations on values)</tt></dd></dl>
<dl><dt><a name="-unit_bbox"><strong>unit_bbox</strong></a>()</dt><dd><tt>Get a 0,0 -> 1,1 Bbox instance</tt></dd></dl>
<dl><dt><a name="-zero"><strong>zero</strong></a>()</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>Float</strong> = 'd'<br>
<strong>IDENTITY</strong> = 0<br>
<strong>LOG10</strong> = 1<br>
<strong>POLAR</strong> = 0</td></tr></table>
@footer@