I just committed the changes I've been working on for the last week to
CVS. These include a new set of transformation classes in extension
code and a rewrite of all the artist constructors. The rational for
both is in the API_CHANGES file (part of CVS), which I'll include
below.
Please let me know if you can build the new code, and if it passes
your tests. There are still a few bugs to work out (known bugs
below). The major reason behind these changes was to implement fast
drawing of large collections of objects (lots of independent line
segments or polygons) using the new matplotlib.collections code (this
will support pcolor and scatter, not done yet). I haven't done
polygon collections yet, but my preliminary tests with line
collections indicate a 5-20x speed up for line collections of
1000-20000 lines. And these tests were before the new, hopefully much
faster, transform architecture was in place. After I get the rest of
the changes and fixes in I'll run some tests against 0.53.1 for
comparison.
These are the problems I know about
-- data lim problem with image; see image_demo2
-- handle space in roman/font mathtext
-- scatter demos whacked
-- fix minor text bboxing problems
-- fix backend image area problem for vertical text in GTK
Also, I did a comprehensive rewrite of mathtext; here are my notes:
factored ft2font stuff out of layout engine and defined an abstract
class for font handling to lay groundwork for ps mathtext. I
rewrote parser and made layout engine much more precise, fixing all
the layout hacks. Added spacing commands \/ and \hspace. Added
composite chars and defined angstrom.
The next release is likely to cause a pain for some due to the API
changes (mostly minor however and not in user space). But for the
first time, I'm fairly happy with the overall design and so I think
the API should be pretty stable for the forseeable future.
And here are the API changes notes
API CHANGES in matplotlib-0.54
Autoscaling:
The x and y axis instances no longer have autoscale view. These are
handled by axes.autoscale_view
Axes creation:
You should not instantiate your own Axes any more using the OO API.
Rather, create a Figure as before and in place of
f = Figure(figsize=(5,4), dpi=100)
a = Subplot(f, 111)
f.add_axis(a)
use
f = Figure(figsize=(5,4), dpi=100)
a = f.add_subplot(111)
That is, add_axis no longer exists and is replaced by
add_axes(rect, axisbg=defaultcolor, frameon=True)
add_subplot(num, axisbg=defaultcolor, frameon=True)
Artist methods:
If you define your own Artists, you need to rename the _draw method
to draw
Bounding boxes.
matplotlib.transforms.Bound2D is replaced by
matplotlib.transforms.Bbox. If you want to construct a bbox from
left, bottom, width, height (the signature for Bound2D), use
matplotlib.transforms.lbwh_to_bbox, as in
bbox = clickBBox = lbwh_to_bbox(left, bottom, width, height)
The Bbox has a different API than the Bound2D. Eg, if you want to
get the width and height of the bbox
OLD
width = self.figure.bbox.x.interval()
height = self.figure.bbox.y.interval()
New
width = self.figure.bbox.width()
height = self.figure.bbox.height()
Object constructors:
You no longer pass the bbox, dpi, or transforms to the various
Artist constructors. The old way or creating lines and rectangles
was cumbersome because you had to pass so many attributes to the
Line2D and Rectangle classes not related directly to the gemoetry
and properties of the object. Now default values are added to the
object when you call axes.add_line or axes.add_patch, so they are
hidden from the user.
If you want to define a custom transformation on these objects, call
o.set_transform(trans) where trans is a Transformation instance.
In prior versions of you wanted to add a custom line in data coords,
you would have to do
l = Line2D(dpi, bbox, x, y,
color = color,
transx = transx,
transy = transy,
)
now all you need is
l = Line2D(x, y, color=color)
and the axes will set the transformation for you (unless you have
set your own already, in which case it will eave it unchanged)
Transformations:
The entire transformation architecture has been rewritten.
Previously the x and y transformations where stored in the xaxis and
yaxis insstances. The problem with this approach is it only allows
for separable transforms (where the x and y transformations don't
depend on one another). But for cases like polar, they do. Now
transformations operate on x,y together. There is a new base class
matplotlib.transforms.Transformation and two concrete
implemetations, matplotlib.transforms.SeparableTransformation and
matplotlib.transforms.Affine. The SeparableTransformation is
constructed with the bounding box of the input (this determines the
rectangular coordinate system of the input, ie the x and y view
limits), the bounding box of the display, and possibily nonlinear
transformations of x and y. The 2 most frequently used
transformations, data cordinates -> display and axes coordinates ->
display are available as ax.transData and ax.transAxes. See
alignment_demo.py which uses axes coords.
Also, the transformations should be much faster now, for two reasons
* they are written entirely in extension code
* because they operate on x and y together, they can do the entire
transformation in one loop. Earlier I did something along the
lines of
xt = sx*func(x) + tx
yt = sy*func(y) + ty
Although this was done in numerix, it still involves 6 length(x)
for-loops (the multiply, add, and function evaluation each for x
and y). Now all of that is done in a single pass.
See unit/transforms_unit.py for many examples using the new
transformations.