On Mon, Nov 17, 2008 at 8:05 AM, Hrafnkell Pálsson <[EMAIL PROTECTED]> wrote:
>
> Hi
>
> I tried you suggestions but it didn't work out for me.
> In the following code I try to save the axes and the grid from figure1 into
> buffer and then restore it on figure2 but figure2.png turns out to be of an
> empty canvas.
>


OK, ever since Jae-Joon clued me into to the importance of the savefig
call, I realized there is a fairly easy solution for your problem.
The problem you are having is that savefig is redrawing the "figure
frame" which is essentially just filling the rectangular background of
the figure canvas.  This is obscuring the background you are trying to
restore.  SO just turn the frame off, and your background will be
revealed in its place.  Here is the example code:

import matplotlib
matplotlib.use('Agg')

import matplotlib.pyplot as plt

plt.close('all')

# make sure we have all the same properties on all figs
figprops = dict(figsize=(8,6), dpi=100, facecolor='white')

fig1 = plt.figure(1, **figprops)
ax1 = fig1.add_subplot(111)
ax1.grid()
fig1.canvas.draw()
background = fig1.canvas.copy_from_bbox(fig1.bbox)
fig1.savefig('figure1.png', dpi=100)


# turn the frame off or it will overwrite the background
fig2 = plt.figure(2, frameon=False, **figprops)
fig2.canvas.restore_region(background)
fig2.savefig('figure2.png', dpi=100)

-------------------------------------------------------------------------
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

Reply via email to