Le jeudi 16 juin 2011 à 07:47 -0700, Alain Francés a écrit :
> Hi Jakob,
> 
> yes your solution works and is more elegant! See the code at the end of this
> message.
> However using the original code with the Agg backend instead of WXAgg also
> works fine, so there is probably a memory leakage problem with WXAgg (see
> the post of David and my reply).
> Thank for your reply and suggestion!

Have you tried to go further and reuse the AxesImage instance created by
imshow? The API is quite not accessible on official matplotlib
documentation but exists (in the matplotlib.image module)

CODE
# BOF
import os, tempfile
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
print '\nBackend:\n' + mpl.get_backend() + '\n'

def plot_density(filename,i,t,psi_Na, fig, image):
    if image is None:
        image = plt.imshow(abs(psi_Na)**2,origin = 'lower')
    else:
        image.set_data(abs(psi_Na)**2)
        # Maybe needs some update here.
    filename = os.path.join(tempfile.gettempdir(), filename + '_%04d.png'%i)
    plt.savefig(filename)
    plt.clf()
    return image

if __name__ == "__main__":
    x = np.linspace(-6e-6,6e-6,128,endpoint=False)
    y = np.linspace(-6e-6,6e-6,128,endpoint=False)
    X,Y = np.meshgrid(x,y)
    k = 1000000
    omega = 200
    times = np.linspace(0,100e-3,100,endpoint=False)
    fig = plt.figure(figsize=(8,6))
    image = None
    for i,t in enumerate(times):
        psi_Na = np.sin(k*X-omega*t)
        image = plot_density('wavefunction',i,t,psi_Na, fig, image)
        print i
    plt.close()
# EOF
-- 
Fabrice Silva


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to