Is really matplotlib this slooow for displaying images ? (sorry again)

I'll spend some time with the profiler looking for some low

    > hanging fruit.

God bless the profiler. It turns out over half of the time to display
this image is spent in the normalizer, which takes image data in an
arbitrary scale and maps into the unit interval

  http://matplotlib.sourceforge.net/matplotlib.colors.html#normalize

The normalizer handles a lot of special cases that you may not need.
In fact, your data may already be normalized. So you can write a
custom normalizer

from pylab import *

def mynorm(X): # do nothing, it's already normalized
    return X

ion()

rc('figure', figsize=(13,12))
X = rand(1600,1600)
figimage(X, cmap=cm.hot, norm=mynorm)

This change alone gives me more than a 2x speedup. So with GTKAgg + a
custom normalizer (in this case a do nothing normalizer) you'll be
running 4-5 times faster than you were before, me thinks.

peds-pc311:~/python/projects/matplotlib> time python ~/test.py --numarray
1.650u 0.450s 0:02.13 98.5% 0+0k 0+0io 4746pf+0w

I'll keep digging through the profiler...

JDH

Test done and this is correct, here are the sets of timing :
first line is without ''mynorm'', second is with ''mynorm''.
time python test.py --Numeric -dTkAgg
10.432u 1.663s 0:12.37 97.7% 0+0k 0+0io 0pf+0w
7.258u 1.302s 0:08.64 98.9% 0+0k 0+0io 0pf+0w

time python test.py --Numeric -dGTKAgg
5.209u 0.845s 0:06.10 99.0% 0+0k 0+0io 0pf+0w
4.226u 0.700s 0:04.98 98.7% 0+0k 0+0io 0pf+0w

time python test.py --numarray -dTkAgg
16.391u 1.036s 0:17.96 96.9% 0+0k 0+0io 0pf+0w
5.690u 0.829s 0:06.85 95.0% 0+0k 0+0io 0pf+0w

time python test.py --numarray -dGTKAgg
8.225u 0.546s 0:08.96 97.7% 0+0k 0+0io 0pf+0w
3.363u 0.445s 0:03.86 98.4% 0+0k 0+0io 0pf+0w

Another factor of 10 and you are faster than Midas.. :slight_smile:

Eric

John Hunter wrote:

···

"John" == John Hunter <jdhunter@...4...> writes:
           
   > I'll spend some time with the profiler looking for some low
   > hanging fruit.

God bless the profiler. It turns out over half of the time to display
this image is spent in the normalizer, which takes image data in an
arbitrary scale and maps into the unit interval

http://matplotlib.sourceforge.net/matplotlib.colors.html#normalize

The normalizer handles a lot of special cases that you may not need.
In fact, your data may already be normalized. So you can write a
custom normalizer

from pylab import *

def mynorm(X): # do nothing, it's already normalized
   return X

ion()

rc('figure', figsize=(13,12))
X = rand(1600,1600)
figimage(X, cmap=cm.hot, norm=mynorm)

This change alone gives me more than a 2x speedup. So with GTKAgg + a
custom normalizer (in this case a do nothing normalizer) you'll be
running 4-5 times faster than you were before, me thinks.

peds-pc311:~/python/projects/matplotlib> time python ~/test.py --numarray
1.650u 0.450s 0:02.13 98.5% 0+0k 0+0io 4746pf+0w

I'll keep digging through the profiler...

JDH

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem