Paste error in subplots using PIL and matplotlib.pylab on MacOS X

Jean-Baptiste Marquette <[email protected]> Mon, 17 Sep 2012 16:49:46 +0200
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
Dear PIL gurus,

I try to paste the same series of images (the Solar System planets) on two subplots of the same figure. The following loop is within a loop on the two subplots :

    print 'Processing Solar System'
    for FileImage in ListImages:
        Planet = os.path.basename(FileImage)[:-9]
        print 'Processing planet', Planet
        PlanetData = SolarSystem.where(SolarSystem.Planet == Planet)
        PlanetImage = Image.open(FileImage)
        if PlanetData.Radius[0] < 2.0: ZoomPlanet = ShrinkTellur * PlanetData.Radius[0] / Earth.Radius[0] * EarthImage.size[1] / PlanetImage.size[1]
        else : ZoomPlanet = ShrinkGiant * PlanetData.Radius[0] / Jupiter.Radius[0] * JupiterImage.size[1] / PlanetImage.size[1]
        PlanetResized = PlanetImage.resize((int(PlanetImage.size[0] * ZoomPlanet), int(PlanetImage.size[1] * ZoomPlanet)))
        Alpha = PlanetResized.split()[3]
        Alpha = ImageEnhance.Brightness(Alpha).enhance(Opacity)
        PlanetResized.putalpha(Alpha)
        if SubPlot == 1: Factor = 1.0
        else: Factor = SnowFactor
        PlanetX, PlanetY = XPixMin + (np.log10(PlanetData.Distance[0] / Factor) - XScalMin) * XFactor, YPixMax - (np.log10(PlanetData.Mass[0]) - YScalMin) * YFactor
        XSize, YSize = PlanetResized.size
        PlanetPos = (int(PlanetX - XSize / 2.0), int(PlanetY - YSize / 2.0))
        PlotImage.paste(PlanetResized, PlanetPos, PlanetResized)
        PlotImage.show()

The show() method proves that everything is fine unless the second subplot is processed: the images on the first one are erased. The images below are obtained by commenting the canvas.draw() instruction, thus anything has been removed but the pasted images. The first one is the first subplot well processed, second subplot still blank, the second is the next subplot, first planet. It is clear that all images have been erased from the previous subplot.

I use the latest PIL version with Agg backend and :

Enthought Python Distribution -- www.enthought.com
Version: 7.3-1 (64-bit)

Python 2.7.3 |EPD 7.3-1 (64-bit)| (default, Apr 12 2012, 11:14:05) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

Any hint welcome,
Cheers
Jean-Baptiste

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig