Hello, I'm having a problem reusing a figure with the savefig command. I want to generate image timeseries with GoogleEarth displaying weather radar data, so my plot geometry is the same always and only the color of the patches which represent measurements changes over time. Now I want those portions of the image, where no precipitation occurs to be transparent so I was thinking about setting the visibility of those Polygons to False and that would be it.
Unfortunately savefig seems to reuse the image it created before when called a second time. I wrote this example code. ########################## #start #set some image parameters figsize = (1.,1.) dpi = 300 rect = [0.,0.,1.,1.] #get figure and axes objects fig = plt.figure(figsize=figsize, dpi=dpi, frameon=False) ax = fig.add_axes(rect, frameon=False) ax.set_aspect(1.0) #create two polygons, one filling the left half of the image # one the right half poly1 = Polygon(([0,0],[0.5,0],[0.5,1],[0,1],[0,0]), fill=True) ax.add_patch(poly1) poly2 = Polygon(([0.5,0],[1,0],[1,1],[0.5,1],[0.5,0]), fill=True) ax.add_patch(poly2) # basic colors black, red, green, blue colors=['#000000','#ff0000','#00ff00','#0000ff'] # switch for the left polygon values =[-1, 1, -1, 1] for value, color in zip(values, colors): if value < 0: poly1.set_visible(False) else: poly1.set_visible(True) poly1.set_facecolor(color) poly2.set_facecolor(color) plt.savefig('test'+color[1:]+'.png',dpi=dpi,format='png',transparent=True) # end ########################## Now, what I expect and what I get is: Test000000.png: black on the right side, transparent with tick marks on the left - this is what I get. Testff0000.png: red on both sides with tick marks visible - This is what I get. Test00ff00.png: green on the right side, transparent on the left. What I get is green on the right and red on the left. So the red from the previous patch has been retained Test0000ff.png: blue on both sides, which is what I get as well. So apparently the plot is updated, but only in places where something is actually drawn. The rest remains unchanged and so transparency is not restored. I tried using clf, cla, deleting objects. In all cases savefig just always produced the first image over and over, most probably because nothing new was drawn. I even tried to remove fig's canvas object, hoping that the library might create a new one, but that only gave me a traceback. Any ideas what I'm doing wrong or how I could solve this problem? Thank you very much in advance, Thomas -- Using Python2.5, matplotlib 0.98.3, numpy 1.1.1, matplotlib.basemap 0.99.1 On WindowsXP SP3, Pentium4 DualCore 3.4GHz, 3GB RAM ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users