Big slowdown showing PNG images


I had a piece of code working perfectly fine with matplotlib 0.87.2.
Now I updated to 0.87.3 and it is about 100 times slower (!).

The code shows a PNG image using axes.imshow.


from pylab import *
from time import asctime, time
import Image

ax = fh.add_subplot(111)
print 'Image intepolation = %s' % rcParams['image.interpolation']
print 'Image aspect = %s' % rcParams['image.aspect']
print 'Date/Time = %s' % asctime()

print "Starting"
image =
print " terminated"

print "Starting imshow"
ax.imshow(image, origin='lower')
print "imshow terminated"

setp(ax.get_xticklabels(), visible=False)
setp(ax.get_yticklabels(), visible=False)
setp(ax.get_xticklines(), visible=False)
setp(ax.get_yticklines(), visible=False)
print 'Execution time [s] = %4.2f' % (t2-t1)


I tried to create a patch but couldn't understand internal details of
matplotlib, so here are the directions:

1 - The offending part is imshow. (not PIL
2 - 0.87.3 imshow has some new code:
        if vmin is not None or vmax is not None:
            im.set_clim(vmin, vmax)

As I do not call imshow with vmax neither vmin this will always fall
into the else clause and call im.autoscale, that is the offending part
on axes.imshow.

Commenting im.autoscale() call makes it fast again, but i don't know
if this is right.

My image is 25K and 2400x1800 black and white PNG. I can send it...

I tried using aspect as 'normal', 'equal' and 'auto' but none had
performance as good as mpl 0.87.2.

Matplotlib 0.87.2 showed figure in less than 0.5 sec, 0.87.3 in about 45 sec.

Should I file a bug report?


Leandro Lameiro