Skip to content

Faster Text drawing needed #347

Closed
Closed

Description

@ddale

Original report at SourceForge, opened Wed Mar 21 08:03:30 2007

Drawing of plots with multiple matplotlib.Text instances is so slow as to be unusable for some applications, such as realtime multiple sequence alignment rendering/viewing (see attachment for a pylab example, resize plot window to see effect).

Some layman's thoughts:

  • Would it be possible to speed things up by implementing some kind of Text Collection?
  • Is antialiasing involved? An option to turn it off would be nice in that case.

SourceForge Comments

On Thu Sep 6 16:07:54 2007, mdboom wrote:

Logged In: YES
user_id=119312
Originator: NO

It appears that the text is re-rendered to a newly allocated buffer each time the text is drawn. Perhaps some caching of text elements would help.

(Mostly just making a note of it for someone else to work this through, or until I have the time.)

SourceForge History

  • On Wed Mar 21 08:03:30 2007, by yohell: File Added: 221568: test.py

Activity

  1. mdboom commented on Jun 21, 2011

    @mdboom
    Member

    This is the OP's attachment:

    import random
    import pylab
    aas = "ACDEFGHIKLMNPQRSTVWXY-"
    fig = pylab.figure()
    xmax = 100
    ymax = 50
    for iX in range(xmax):
        for iY in range(ymax):
            pylab.text(iX + 0.5,
                       iY + 0.5,
                       random.choice(aas),
                       family = 'sans-serif',
                       size = 6,
                       horizontalalignment = 'center',
                       verticalalignment = 'center')
    pylab.xlim(0, xmax)
    pylab.ylim(0, ymax)
    pylab.savefig("test.png")
  2. butterw commented on Jun 21, 2011

    @butterw

    +1 in favor of adding a TextCollection class to matplotlib

  3. mdboom commented on Jun 22, 2011

    @mdboom
    Member

    There's really two problems here:

    Rendering text with the Agg backend is slow because it assumes the text may be rotated, which requires an affine transformation and filtering at each pixel. I have a faster text blitting implementation (for non-rotated text only) on my 347_fast_text branch. This change provides about a 20% speedup on this example. Unfortunately, this causes a lot of the regression tests to now fail since the text is crisper (and theoretically more correct). I will need to wade through the regression test results and update baseline images before merging this.

    The need for a TextCollection remains, though from profiling, it's not clear that the lack of one is the bottleneck here.

  4. ghost assigned on Jun 22, 2011
  5. pelson commented on Jun 30, 2012

    @pelson
    Member

    @mdboom: Seems like a 20% speedup & crisper text are worthwhile pursuits. Do you have any update on this? Are you considering making a PR out of the change?

  6. added this to the milestone on Aug 18, 2014
  7. Tillsten commented on Sep 30, 2015

    @Tillsten
    Contributor

    This would be really nice. After doing some profiling text rendering and complicated tick handling are main reasons for mpl slowness.

  8. added a commit that references this issue on Oct 30, 2015
    0851732
  9. added a commit that references this issue on Nov 2, 2015
    340c256
  10. added a commit that references this issue on Nov 5, 2015
    c457f01
  11. added a commit that references this issue on Nov 5, 2015
    a340827
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions