On Thu, Apr 23, 2015 at 12:05 PM, Virgil Stokes <v...@it.uu.se
<mailto:v...@it.uu.se>> wrote:
Thanks for your reply to my post, Jerzy.
On 23-Apr-2015 13:18, Jerzy Karczmarczuk wrote:
Le 23/04/2015 12:22, Virgil Stokes a écrit :
The following interesting example (random_data.py) is posted at:
http://matplotlib.org/1.4.2/examples/animation/random_data.html
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
Yes, I forgot to include this
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True: yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
plt.show()
This codes works; but, I am very confused by it. For example:
1. There are 3 positional arguments given for
animation.FuncAnimation; but, in the
API documentation for this class
(http://matplotlib.org/api/animation_api.html), only
two positional arguments are shown.
The third one is the third one,
"/frames/ can be a generator, an iterable, or a number of frames."
This makes very little sense to me --- what does "or a number of
frames" mean?
The name "data_gen" could suggest its meaning (after having read the
doc).
I am not sure what you are referencing as "the doc"; but I did read
the documentation several times and English is my native language.
Note please that the keyword parameters are specified extra.
I am aware of this. Perhaps, I am a Python dummy --- when I see
something like value = None in a Python API argument, I interpret
this as a keyword argument and not a generator.
2. data, the argument to the update function seems to be undefined.
FuncAnimation usually passes the frame number: 0, 1, 2, ... as the
first parameter of the update function, when "frames" is None, or
the number of frames. If - as here - the third parameter is a
generator, it passes the yielded data to update.
It may be used or not.
Ok, I understand that better now. But, you say "or *the number* of
frames" but the documentation reads "or *a number* of frames" ---
what does this mean?
And I still do not understand how to use the first argument of the
function to be called for the animation. In another animation example
(histogram.py), the animation function is defined by:
def animate(i):
# simulate new data coming in
data = np.random.randn(1000
n, bins = np.histogram(data, 100)
top = bottom + n
verts[1::5,1] = top
verts[2::5,1] = top
This works of course; but, why is the "i" required? There is no other
reference to it in the entire script. If I remove it; i.e. use def
animate(): I get the following error:
TypeError: animate() takes no arguments (1 given)
I do not understand how this explains the fact that the function no
longer has any arguments. Please explain the meaning of this error
message?
Please, in such cases test your programs by adding some simple
tracing contraptions, say, print(data) inside update.
I did this and more before posting my email. I would not have posted
this unless I thought it was necessary. And I thought one purpose of
this user group was to help people --- even if they ask a question
which may be annoying or "stupid" in some subscribers opinion. I try
to remember what a very wise teacher once said --- "there is no such
thing as a stupid question".
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live
exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
<mailto:Matplotlib-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/matplotlib-users