[Image-SIG] Paste error in subplots using PIL and matplotlib.pylab on MacOS X

Jean-Baptiste Marquette marquett at iap.fr
Mon Sep 17 17:27:38 CEST 2012


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20120917/9859fb1b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2012-09-17 16.31.03.png
Type: image/png
Size: 27660 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20120917/9859fb1b/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2012-09-17 16.31.33.png
Type: image/png
Size: 19787 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/image-sig/attachments/20120917/9859fb1b/attachment-0003.png>


More information about the Image-SIG mailing list