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.
>
> #!/usr/bin/env /opt/python/bin/python
> # encoding: utf-8
> import matplotlib
> if not matplotlib.get_backend()=='agg':
>    matplotlib.use('Agg')
> import pylab
>
> figure1 = pylab.figure(1)
> axes1 = pylab.gca()
> axes1.grid()
> canvas1 = axes1.figure.canvas
> background = canvas1.copy_from_bbox(axes1.bbox)
> figure1.savefig('figure1.png')

The only problem I could see with your code is that you need to force
a draw before copying the background.  But when I added the draw, and
then further simplified to reuse the same canvas, I still am not
seeing the restored region.  I will need to do further digging to see
what is going wrong, but the problem appears both on the maintenance
branch and the trunk.  Here is my modified test script:

    import matplotlib
    matplotlib.use('Agg')

    import matplotlib.pyplot as plt

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

    fig1.clf()


    #figure2 = pylab.figure(2)
    #canvas2 = figure2.canvas
    fig1.canvas.restore_region(background)
    fig1.savefig('figure2.png')


JDH

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