Στις 23/01/2012 06:52 μμ, ο/η Tony Yu έγραψε:


2012/1/23 Gousios George <gg...@windowslive.com <mailto:gg...@windowslive.com>>

    Στις 21/01/2012 07:43 μμ, ο/η Gousios George έγραψε:
    Στις 21/01/2012 07:05 μμ, ο/η Tony Yu έγραψε:


    On Sat, Jan 21, 2012 at 11:31 AM, Gousios George
    <gg...@windowslive.com <mailto:gg...@windowslive.com>> wrote:

        Στις 21/01/2012 04:54 μμ, ο/η Tony Yu έγραψε:


        On Sat, Jan 21, 2012 at 9:07 AM, Gousios George
        <gg...@windowslive.com <mailto:gg...@windowslive.com>> wrote:

            Hello , i have the following code in matlab and trying
            to do it in
            matplotlib.

            I have this code in matlab (in a function showGraphs):
            ...
            m = size(myList, 3);
            for k = 1:m
                g = myList(:, :, k);
                image(g + 1)
                axis off
                axis square
                M(k) = getframe;
            end;

            and in another file (another function):
            ...
            M = showGraphs(grids)
            movie(M, 1)



            I did so far:

            def showGraphs(data):
                data=sc.array([data])
                n=sc.shape(data)[2]
                for k in range(n):
                    mydata=data[:,:,k]
                    #plt.imshow(mydata+1)    -->> this doesn't work

            Also ,in order to do the animation :

            grids=...(result from another function)
            result=showGraph(grids)
            fig=plt.figure()
            ani=animation.FuncAnimation(fig,result,interval=30,blit=True)
            plt.show()

            Right now the program says "TypeError: 'NoneType'
            object is not
            callable" (it has errors in the animation call)

            What should be my approach to this in order to have the
            animation?

            Thank you!


        You're getting that error because the second argument to
        FuncAnimation (`result` in your example) should be a
        function (not always; see example 2 linked below). Right
        now, if your `showGraphs` function is defined in full, it
        returns a value of None, which gets saved to `result`
        (hence the error).

        You should take a look at some of the image animation
        examples (ex1
        
<http://matplotlib.sourceforge.net/examples/animation/dynamic_image.html>,
        ex2
        
<http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html>).

        -Tony


        I did now :


        def showGraphs(data):
            data=sc.array([data])
            n=sc.shape(data)[2]
            ims=[]

            for k in range(n):
                mydata=data[:,:,k]
                im=plt.imshow(mydata+1)
                ims.append([im])
            return ims

        and now it gives me "TypeError: Invalid dimensions for image
        data.


    Please post short, but executable examples when possible. I'm
    not sure what your data looks like, but your call to `sc.array`
    is strange (I'm not sure why you have square brackets, which
    effectively adds an unnecessary dimension to your data).

    The code attached below should work.

    Cheers,
    -Tony

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.animation import ArtistAnimation


    fig = plt.figure()

    def showGraphs(data):
        data = np.asarray(data) # unnecessary in this example
        n = np.shape(data)[2]

        ims = []
        #for mydata in np.rollaxis(data, -1):
        for k in range(n):
            mydata = data[:, :, k]
            im = plt.imshow(mydata)
            ims.append([im])
        return ims

    # 5 frames of a random 20 x 20 image
    data = np.random.uniform(size=(20, 20, 5))
    ims = showGraphs(data)

    ani = ArtistAnimation(fig, ims)
    plt.show()
    Now,it gives me 2 figures (why 2?) but empty.(maybe i didn't
    convert right the matlab code below?)
    The data in the showGraphs function is the result from this
    function (in matlab):
    .........
    grids = zeros(n, n, t + 1);
    grids(:, :, 1) = rest;
    for i = 2:(t + 1)
        Extended = extendLat1(rest);
        rest = applyExtended(Extended);
        grids(:, :, i) = rest;
    end;

    And i did this in python:

       grids=sc.zeros((area,area,t+1))
        rest=grids[:,:,0]
        for i in range(1,t):
            extended=extend(rest)
            rest=apply_extend(extended)
            grids[:,:,i]=rest
        return grids

    Thanks for helping!

    Any help?Thanks!

Sorry, but could you be a bit clearer:
* Did the example I provide work for you?
* Assuming it did, are you essentially replacing `data` in my example with `grids` in this most recent example? * I don't get 2 figures: are you asking about the code from my last message?
* Please provide a minimal, *executable* example

-Tony
Ok,i 'll try!

1) Yes,your example works fine.
2) Yes,i return grids from another function (work) doing :

    grids=work(area,...,time)
    result=showGraphs(grids)
    ani=ArtistAnimation(fig,result)
    plt.show()

The contents of the work function are shown above.
I just want to make sure that i have done the conversion from matlab right.
Maybe the problem is somewhere else?

Thank you.

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to