Re: [Matplotlib-users] Animation module: every loop takes more and more time

2013-05-29 Thread zetah
Benjamin Root wrote:
>The init() function only happens once.  So, each call to 
>ax.contourf() just
>simply adds more contours on top of the previous (you just don't 
>see them
>because you don't have masked regions or transparency).  I would 
>suggest
>doing an ax.cla() in the animate() function before doing 
>ax.contourf().

It's like you said.
Thanks for assistance :)

Cheers


--
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animation module: every loop takes more and more time

2013-05-29 Thread Benjamin Root
On Wed, May 29, 2013 at 3:03 PM, zetah  wrote:

> Please consider this small script:
>
>
The init() function only happens once.  So, each call to ax.contourf() just
simply adds more contours on top of the previous (you just don't see them
because you don't have masked regions or transparency).  I would suggest
doing an ax.cla() in the animate() function before doing ax.contourf().

Cheers!
Ben Root
--
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Animation module: every loop takes more and more time

2013-05-29 Thread zetah
Please consider this small script:


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

def init():
return ax.cla()

def animate(i):
global t
r = np.random.random(10)
c = np.sin(2 * np.pi * r) * np.vstack(np.cos(2 * np.pi * r))
print(time() - t)
t = time()
return ax.contourf(c)


if __name__ == '__main__':
t = time()
fig = plt.figure()
ax = fig.add_subplot(111)
anim = animation.FuncAnimation(fig, animate, init_func=init,
   frames=100,
   interval=15,
   blit=True)
anim.save('test.mp4', fps=15, extra_args=['-vcodec', 'libx264'])



The output from this script is as follows:


0.2173515
0.375
0.2826485
0.3123624
0.26500010490
0.3126376
0.3586757
0.3286866
0.34399986267
0.375
0.40600013732
0.3913242
0.42200016975
0.46899986267
0.5
0.5163242
0.5
0.5463133
0.5786866
0.57799983024
0.59400010108
0.6086757
0.6413242
0.65599989891
0.7336757
0.71900010108
0.7336757
0.7663242
0.7963133
0.8123624
1.0463134
0.8613351
0.8913242
0.90600013732
0.9213133
0.9213133
1.0
1.1086758
1.0163242
1.03099989891
1.0623624
1.1113351
1.45299983025
1.21900010109
1.3423515
1.3126376
1.35900020599
1.39099979401
1.391049
1.4376376
1.4213134
1.4536866
1.4836758
1.5
1.5
1.54700016975
1.5463134
1.625
1.625
1.625
1.6576485
1.6873624
1.6713134
1.75
1.7336758
1.7336758
1.7826485
1.8123624
1.8286866
1.858951
1.8423515
1.9373624
1.9376376
1.9836758
1.96900010109
2.0463134
2.03099989891
2.03100013733
2.0626376
2.0623624
2.1086758
2.125
2.1713134
2.1413242
2.1873624
2.21900010109
2.2349998951
2.2650001049
2.28100013733
2.28099989891
2.2960381
2.3289619
2.375
2.3586758
2.4213134
2.46900010109
2.4673515
2.48500013351
2.5
2.5163242


So every loops is slower and slower. Now, my original script is more 
complicated, and when it reaches 100th frame the single loop takes half a 
minute to finish compared to half a second after the first loop. Can someone 
suggest what is wrong with the above code, and how to avoid this time 
aggregation on every loop?

Thanks


--
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Animation module

2012-02-20 Thread Allen Hathaway
Worked like a charm.  Thanks.

 

Allen

 

From: ben.v.r...@gmail.com [mailto:ben.v.r...@gmail.com] On Behalf Of
Benjamin Root
Sent: Monday, February 20, 2012 3:21 PM
To: Allen Hathaway
Cc: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Animation module

 

 

On Mon, Feb 20, 2012 at 12:32 PM, Allen Hathaway
 wrote:

I downloaded the Windows installer and installed matplotlib.  I tried to
run one of the examples from the examples directory - animate_decay -
and got the following error:

 

Traceback (most recent call last):

  File "C:\Bin\Python Scripts\plot_decay.py", line 3, in 

import matplotlib.animation as animation

ImportError: No module named animation

 

What did I do wrong?

 

Allen

 


Chances are, an older version of matplotlib is still installed.  Clean
out all matplotlib installs and reinstall the current one.  (Note: need
v1.1.0 and greater for the animation module).

Also, please keep in mind the animation module is very much an
experiment and we greatly welcome feedback on how it works for you!

Cheers!
Ben Root

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


Re: [Matplotlib-users] Animation module

2012-02-20 Thread Benjamin Root
On Mon, Feb 20, 2012 at 12:32 PM, Allen Hathaway
wrote:

> I downloaded the Windows installer and installed matplotlib.  I tried to
> run one of the examples from the examples directory – animate_decay – and
> got the following error:
>
> ** **
>
> Traceback (most recent call last):
>
>   File "C:\Bin\Python Scripts\plot_decay.py", line 3, in 
>
> import matplotlib.animation as animation
>
> ImportError: No module named animation
>
> ** **
>
> What did I do wrong?
>
> ** **
>
> Allen
>
>
Chances are, an older version of matplotlib is still installed.  Clean out
all matplotlib installs and reinstall the current one.  (Note: need v1.1.0
and greater for the animation module).

Also, please keep in mind the animation module is very much an experiment
and we greatly welcome feedback on how it works for you!

Cheers!
Ben Root
--
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


[Matplotlib-users] Animation module

2012-02-20 Thread Allen Hathaway
I downloaded the Windows installer and installed matplotlib.  I tried to
run one of the examples from the examples directory - animate_decay -
and got the following error:

 

Traceback (most recent call last):

  File "C:\Bin\Python Scripts\plot_decay.py", line 3, in 

import matplotlib.animation as animation

ImportError: No module named animation

 

What did I do wrong?

 

Allen

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


Re: [Matplotlib-users] Animation module

2011-11-03 Thread Benjamin Root
On Thu, Nov 3, 2011 at 12:51 PM, Stuart Mumford wrote:

> Hello,
>
> I discovered the (wonderful) animation module in the v1.1 release today.
>
> However I think I may have quickly outgrown it a bit!
>
> I am plotting some simulation data see:
> http://dl.dropbox.com/u/2796140/mhdmodes_3.mp4 for an example made with
> the animation class.
>
> There is one thing missing from the above, which is colour bars!
>
> I have created the animation using the ArtisitAnimation class because each
> frame takes about 1-2 seconds to calculate the magnetic field lines, so
> using FuncAnimate would result in a very slow animation.
>
> The problem is that I can not add a colorbar instance to the list of
> artists that the animator draws as it is not an artist instance.
>
> This is a slightly modified version of the example [
> http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html]
> that shows my problem:
>
> #!/usr/bin/env python
>>
>> """
>>
>> An animated image
>>
>> """
>>
>> import numpy as np
>>
>> import matplotlib.pyplot as plt
>>
>> import matplotlib.animation as animation
>>
>> fig = plt.figure()
>>
>> def f(x, y):
>>
>> return np.sin(x) + np.cos(y)
>>
>> x = np.linspace(0, 2 * np.pi, 120)
>>
>> y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
>>
>> # ims is a list of lists, each row is a list of artists to draw in the
>>
>> # current frame; here we are just animating one artist, the image, in
>>
>> # each frame
>>
>> ims = []
>>
>> for i in range(60):
>>
>> x += np.pi / 15.
>>
>> y += np.pi / 20.
>>
>> im = plt.imshow(f(x, y))
>>
>> cb = plt.colorbar()
>>
>> ims.append([im, cb])
>>
>> ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
>>
>> repeat_delay=1000)
>>
>> plt.show()
>>
>>
> Which generates the following error
>
>> Traceback (most recent call last):
>>   File "/home/stuart/Documents/VAC/sac_anim_axtest.py", line 28, in
>> 
>> repeat_delay=1000)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 356, in __init__
>> TimedAnimation.__init__(self, fig, *args, **kwargs)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 304, in __init__
>> Animation.__init__(self, fig, event_source=event_source, *args,
>> **kwargs)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 53, in __init__
>> self._init_draw()
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 363, in _init_draw
>> artist.set_visible(False)
>> AttributeError: Colorbar instance has no attribute 'set_visible'
>>
>
>
>
> I attempted to add the colorbar to a AxesSubplot instance and then draw
> the axes in the artist list, however when I add a Axes instance to the
> artist list I get a wonderful error:
>
>
> Traceback (most recent call last):
>>   File
>> "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py",
>> line 122, in _on_timer
>> TimerBase._on_timer(self)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py",
>> line 1092, in _on_timer
>> ret = func(*args, **kwargs)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 315, in _step
>> still_going = Animation._step(self, *args)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 177, in _step
>> self._draw_next_frame(framedata, self._blit)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 197, in _draw_next_frame
>> self._post_draw(framedata, blit)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 220, in _post_draw
>> self._blit_draw(self._drawn_artists, self._blit_cache)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
>> 235, in _blit_draw
>> a.axes.draw_artist(a)
>>   File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line
>> 1994, in draw_artist
>> assert self._cachedRenderer is not None
>> AssertionError
>>
>
>  I also saw the subplots animation example [
> http://matplotlib.sourceforge.net/examples/animation/subplots.html],
> however that is also based on FuncAnimate, would there be a way to create
> something similar for ArtistAnimate?
>
> Thanks
> Stuart
>
>
Do you need the colorbar scale to change with each frame?  If not, you can
create a wholly independent colorbar like so:

cb = mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm)

where 'cax' I usually get by using the axes_grid1 toolkit to pre-allocate a
spot for a colorbar axes (as opposed to using fig.add_subplots()).

However, if you need to the colorbar to change with the frames, then I
would use the FuncAnimator, but a little differently than you are probably
imagining.  The fig.colorbar() function requires a ScalarMappable object
(such as an object from imshow()).  What I would do is "prime the pump" by
creating the first frame.  Then create a func animator that calls a
function that loads the cached results based on an index number and
di

[Matplotlib-users] Animation module

2011-11-03 Thread Stuart Mumford
Hello,

I discovered the (wonderful) animation module in the v1.1 release today.

However I think I may have quickly outgrown it a bit!

I am plotting some simulation data see:
http://dl.dropbox.com/u/2796140/mhdmodes_3.mp4 for an example made with the
animation class.

There is one thing missing from the above, which is colour bars!

I have created the animation using the ArtisitAnimation class because each
frame takes about 1-2 seconds to calculate the magnetic field lines, so
using FuncAnimate would result in a very slow animation.

The problem is that I can not add a colorbar instance to the list of
artists that the animator draws as it is not an artist instance.

This is a slightly modified version of the example [
http://matplotlib.sourceforge.net/examples/animation/dynamic_image2.html]
that shows my problem:

 #!/usr/bin/env python
>
> """
>
> An animated image
>
> """
>
> import numpy as np
>
> import matplotlib.pyplot as plt
>
> import matplotlib.animation as animation
>
> fig = plt.figure()
>
> def f(x, y):
>
> return np.sin(x) + np.cos(y)
>
> x = np.linspace(0, 2 * np.pi, 120)
>
> y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
>
> # ims is a list of lists, each row is a list of artists to draw in the
>
> # current frame; here we are just animating one artist, the image, in
>
> # each frame
>
> ims = []
>
> for i in range(60):
>
> x += np.pi / 15.
>
> y += np.pi / 20.
>
> im = plt.imshow(f(x, y))
>
> cb = plt.colorbar()
>
> ims.append([im, cb])
>
> ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
>
> repeat_delay=1000)
>
> plt.show()
>
>
Which generates the following error

> Traceback (most recent call last):
>   File "/home/stuart/Documents/VAC/sac_anim_axtest.py", line 28, in
> 
> repeat_delay=1000)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 356, in __init__
> TimedAnimation.__init__(self, fig, *args, **kwargs)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 304, in __init__
> Animation.__init__(self, fig, event_source=event_source, *args,
> **kwargs)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 53, in __init__
> self._init_draw()
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 363, in _init_draw
> artist.set_visible(False)
> AttributeError: Colorbar instance has no attribute 'set_visible'
>



I attempted to add the colorbar to a AxesSubplot instance and then draw the
axes in the artist list, however when I add a Axes instance to the artist
list I get a wonderful error:


Traceback (most recent call last):
>   File
> "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py",
> line 122, in _on_timer
> TimerBase._on_timer(self)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py",
> line 1092, in _on_timer
> ret = func(*args, **kwargs)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 315, in _step
> still_going = Animation._step(self, *args)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 177, in _step
> self._draw_next_frame(framedata, self._blit)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 197, in _draw_next_frame
> self._post_draw(framedata, blit)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 220, in _post_draw
> self._blit_draw(self._drawn_artists, self._blit_cache)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/animation.py", line
> 235, in _blit_draw
> a.axes.draw_artist(a)
>   File "/usr/lib64/python2.7/site-packages/matplotlib/axes.py", line 1994,
> in draw_artist
> assert self._cachedRenderer is not None
> AssertionError
>

 I also saw the subplots animation example [
http://matplotlib.sourceforge.net/examples/animation/subplots.html],
however that is also based on FuncAnimate, would there be a way to create
something similar for ArtistAnimate?

Thanks
Stuart
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users