how to make matplotlib faster?

For me, this block (run twice for a plot()) typically takes

    > at least 50% of the plot time. Commenting out the
    > tick.draw(renderer) and the following two 'extent' lines
    > roughly doubles the drawing rate (though no grid or ticks
    > are shown). I was surprised by this, but have not tracked it
    > down much beyond this. I'm not using mathtext in the labels
    > and had only standard numerical Tick labels in this example.

    > I don't know if this is applicable to the slowness of the
    > contour plots or error bars or if collections would help
    > here. But it doesn't seem like tick drawing should be the
    > bottleneck. Anyway, this seems like a simple place to test
    > in other situations, and may be a good place to look for
    > possible optimizations.

This is a known bottleneck. Text layout is non-trivial in matplotlib.
Put it this way: you don't get multiline text with arbitrary rotation,
font properties, horizontal, vertical, and multiline alignment for
free. Take a look at matplotlib.text.Text._get_layout.

I do cache the layout information because I've seen this performance
hit on animated demos before. But if your text properties are
changing, caching doesn't help. The cache key is returned by

It is probably worthwhile to run your animation through the profiler
so we can get a better idea of where exactly the problems are. I
think the matrix multiplication that _get_layout uses for rotations is
slow. It would be possible to special case the most common case
(rotation angle = 0) for some speedups, but the code is already fairly
hairy so I've been resisting special casing it.

FYI, the wxagg backend uses string methods to transfer the agg image
to the canvas. tk and gtk use extension code. fltk uses a python
buffer object. I investigated the latter for wxagg but couldn't make
it work. You may want to look into FigureCanvasWxAgg.draw to see if
you can do this image transfer faster, possibly adding some extension
code. If you do go the extension code route, I suggest you try/except
the import on your extension code and fall back on the string method
already in place.

Oh, I added "newville" to the list of CVS developers. Everyone,
welcome Matt, the new wx maintainer!