Real-time graphs

M

MJR

Hi,
just wondering what options I would have if I wanted to use Python to
produce real-time graphs. Is there any plotting package suitable for
this.

Thanks,
Mike
 
S

Sean Berry

Hi,
just wondering what options I would have if I wanted to use Python to
produce real-time graphs. Is there any plotting package suitable for
this.

I don't know about plotting packages... but I used PIL (Python Imaging
Library) to create some dynamic graphs.

Hopefully someone has something to help because I might be able to use them
as well for some upcoming projects.
 
K

Kristofer Pettijohn

MJR said:
Hi,
just wondering what options I would have if I wanted to use Python to
produce real-time graphs. Is there any plotting package suitable for
this.

For grabbing data and producing graphs (see
http://newsfeed.visi.com/~kpettijohn/stats/ for a live example) I use
rrdtool and the py-rrdtool module to dynamically get those graphs.

If you're looking to dynamically give the module numbers from other
sources and generate graphs based on that, I'll leave the othes up
to giving suggestions :)

Kristofer
 
J

John Hunter

MJR> Hi, just wondering what options I would have if I wanted to
MJR> use Python to produce real-time graphs. Is there any plotting
MJR> package suitable for this.

This was discussed at length on this list fairly recently - see

http://groups.google.com/[email protected]#link2

One important consideration is what you mean by real-time - do you
mean real time in the sense of preemptable kernel or in the sense of
dynamically updating 10-30 times per second; what kind of refresh
rates do you need?

JDH
 
G

Grant Edwards

just wondering what options I would have if I wanted to use Python to
produce real-time graphs.

What do you mean by "real-time"?

If you want to display a "live" waveform at 50fps, then I'm not
aware of anything.

I use gnuplot-py quite successfully to do oscilloscope and
strip-chart type displays at up to about 2-3 frames per second.
 
M

MJR

Grant Edwards said:
What do you mean by "real-time"?

If you want to display a "live" waveform at 50fps, then I'm not
aware of anything.

Need to display data read from telemetry systme. Data might change in
order of 1000/s. Not every sample will be displayed, but still need
something close to 100sps
 
J

John Hunter

MJR> Need to display data read from telemetry systme. Data might
MJR> change in order of 1000/s. Not every sample will be
MJR> displayed, but still need something close to 100sps --

Hmm, I assume sps means samples per second? I was thinking about
refresh rates (frames per second) above, which is a different
question. So the next question is, what kinds of refresh rates do you
need?

I wrote a little test script in matplotlib that randomly generates
1000 x,y points and displays them. It can do about 12 frames per
second on my system (GTKAgg backend on a 3GHz P4 running linux). With
only 100 points being plotted per frame, I get 40 FPS. For more
complex plots, eg those which include images, or for other matplotlib
backends, this will be slower.

Here is a demo script - replace the random_data with your real data
and you're off to the races. Note that matplotlib comes with a number
of examples for animations and dynamic images in the examples
subdirectory of the src distribution, or at
http://matplotlib.sf.net/examples

#!/usr/bin/env python
"""
Dynamically update line data
"""
import sys, time, os, gc
import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import rcParams

from matplotlib.matlab import *
import gtk

fig = figure(1)
a = subplot(111)
def rand_data(N=100):
x = arange(N)*0.001
y = rand(N)
return x,y

x,y = rand_data()
line, = plot(x,y,'-')


manager = get_current_fig_manager()
cnt = 0
tstart = time.time()
def updatefig(*args):
global cnt, start
x,y = rand_data()
line.set_data(x,y)
manager.canvas.draw()
cnt += 1
if cnt==50:
print 'FPS', cnt/(time.time() - tstart)
return gtk.FALSE
return True


cnt = 0

gtk.idle_add(updatefig)
show()





JDH
 
G

Grant Edwards

Need to display data read from telemetry systme. Data might change in
order of 1000/s. Not every sample will be displayed, but still need
something close to 100sps

If you want to do 100 frames per second, you're going to have
to use gaming/animation techniques: Xv extensions,
double-buffering of frames, etc.
 
P

Peter Hansen

Grant said:
If you want to do 100 frames per second, you're going to have
to use gaming/animation techniques: Xv extensions,
double-buffering of frames, etc.

Not to mention using a special monitor with a refresh rate
well above the usual. ;-)

I think he meant "samples per second", though, but didn't
give enough info for us to know his minimum refresh rate.

-Peter
 
A

andrea valle

Hi to all,
I'd like to access the parameter list of a function (or better of a
method) in order to generate GUI elements.
That is.
If I have this:
print foo_param

I'd like to have something like:

My idea is to use the foo_params strings in Tkinter as text for Label
and as variables for Entries.

What have I to do?

Thanks a lot as usual

Best

-a-


_____________________________________________________________________
For your security, this mail has been scanned and protected by Inflex
 
G

Grant Edwards

Not to mention using a special monitor with a refresh rate
well above the usual. ;-)

Yup, trying to do multiple frames/update will resulting tearing
of the displays. To get the best looking results he probably
wants to max out his frame rate at the display update rate, and
synchronize buffer flips with vertical blanking period.
I think he meant "samples per second",

I was assuming he wanted to display a new frame for each
sample. If there are 5000 samples per frame, then life just
got a whole lot easier for him.
 
A

andrea valle

Richie thanks a lot, it works perfectly.
Anycase, I don't know exactly what's happening.
Could you be so kind to comment the code?
(or to point to some docs: I wasn't able to found the refercence. I
found func_code before writing to the list, but not the method you
invoke)

Best

-a-

[Andrea]
I'd like to access the parameter list of a function

You can do it like this:
... foo_local = foo_param1
...
code = foo.func_code
print code.co_varnames[:code.co_argcount]
('foo_param1', 'foo_param2')
Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
(e-mail address removed)


_____________________________________________________________________
For your security, this mail has been scanned and protected by Inflex
 
J

Josiah Carlson

Grant Edwards said:
If you want to do 100 frames per second, you're going to have
to use gaming/animation techniques: Xv extensions,
double-buffering of frames, etc.

Or generate the image and modify it in-place (not practical for some
kinds of graphs). Then the only slowdown is transferring the image to
the client.

- Josiah
 
W

William Park

MJR said:
Need to display data read from telemetry systme. Data might change in
order of 1000/s. Not every sample will be displayed, but still need
something close to 100sps

If you mean 100 graphs per second, I don't think commodity PC hardware
will do it.

Displaying 1 graphs/second, might be more reasonable, depending on the
quality of graph you want. Gnuplot is the canonical answer. But, if
you want fast character plot on your terminal (just for visual check),
then you could probably display more than 1 graphs/second.
 
J

Jean Brouwers

Take a look at the getargspec() function in the inspect module. It
returns a 4-tuple and the first item of that tuple is a list of the
parameter names of a function or method.

<pre>
import inspect
def foo(p1, p2):
pass
print inspect.getargspec(foo)

results in:

(['p1', 'p2'], None, None, None)

</pre>

The second item is the name of the *args argument, the third is the
name of the **kwds argument and the last item is a tuple of the values
of the kwds args.

More details in

<http://docs.python.org/lib/inspect-classes-functions.html>

and on page 381 of the (outstanding, IMO) book "Python in a Nutshell",
1st edition.


/Jean Brouwers
ProphICy Semiconductor, Inc.
 
A

andrea valle

Thanks to all for the replies.
Now, sorry, something related.
Suppose I have a string and I'd like to create a variable with its name.
How can I do that?

I tried to create the variable text assigning to it the value "text"
with this:
But it raises an error.

Thanks as usual

Best

-a-




Take a look at the getargspec() function in the inspect module. It
returns a 4-tuple and the first item of that tuple is a list of the
parameter names of a function or method.

<pre>
import inspect
def foo(p1, p2):
pass
print inspect.getargspec(foo)

results in:

(['p1', 'p2'], None, None, None)

</pre>

The second item is the name of the *args argument, the third is the
name of the **kwds argument and the last item is a tuple of the values
of the kwds args.

More details in

<http://docs.python.org/lib/inspect-classes-functions.html>

and on page 381 of the (outstanding, IMO) book "Python in a Nutshell",
1st edition.


/Jean Brouwers
ProphICy Semiconductor, Inc.



andrea valle said:
Hi to all,
I'd like to access the parameter list of a function (or better of a
method) in order to generate GUI elements.
That is.
If I have this:

print foo_param

I'd like to have something like:


My idea is to use the foo_params strings in Tkinter as text for Label
and as variables for Entries.

What have I to do?

Thanks a lot as usual

Best

-a-


_____________________________________________________________________
For your security, this mail has been scanned and protected by Inflex
Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
(e-mail address removed)
 
J

Jean Brouwers

The simplest thing to do would be to make the variable an attribute of
a class instance.

class Vars: pass
# create one instance
v = Vars()
# add vars as needed
v.text = "text"
v.int = 12
...
print v.text, v.int

Is this what you need?

/Jean Brouwers
ProphICy Semiconductor, Inc.


andrea valle said:
Thanks to all for the replies.
Now, sorry, something related.
Suppose I have a string and I'd like to create a variable with its name.
How can I do that?

I tried to create the variable text assigning to it the value "text"
with this:
But it raises an error.

Thanks as usual

Best

-a-




Take a look at the getargspec() function in the inspect module. It
returns a 4-tuple and the first item of that tuple is a list of the
parameter names of a function or method.

<pre>
import inspect
def foo(p1, p2):
pass
print inspect.getargspec(foo)

results in:

(['p1', 'p2'], None, None, None)

</pre>

The second item is the name of the *args argument, the third is the
name of the **kwds argument and the last item is a tuple of the values
of the kwds args.

More details in

<http://docs.python.org/lib/inspect-classes-functions.html>

and on page 381 of the (outstanding, IMO) book "Python in a Nutshell",
1st edition.


/Jean Brouwers
ProphICy Semiconductor, Inc.

def foo( foo_param1, foo_param2):


andrea valle said:
Hi to all,
I'd like to access the parameter list of a function (or better of a
method) in order to generate GUI elements.
That is.
If I have this:

def foo( foo_param1, foo_param2):
print foo_param

I'd like to have something like:

print foo.param_list
'foo_param1', 'foo_param2'

My idea is to use the foo_params strings in Tkinter as text for Label
and as variables for Entries.

What have I to do?

Thanks a lot as usual

Best

-a-


_____________________________________________________________________
For your security, this mail has been scanned and protected by Inflex
Andrea Valle
Laboratorio multimediale "G. Quazza"
Facoltà di Scienze della Formazione
Università degli Studi di Torino
(e-mail address removed)
 
T

Terry Reedy

andrea valle said:
Suppose I have a string and I'd like to create a variable with its name.
How can I do that?

globals['varname'] = 3

difficult or impossible for function locals

Terry J. Reedy
 
P

Peter Otten

Terry said:
andrea valle said:
Suppose I have a string and I'd like to create a variable with its name.
How can I do that?

globals['varname'] = 3

difficult or impossible for function locals

Not difficult - only ugly, slow, and dangerous:
.... a, b, c = 1, 2, 3
.... # FIXME put code to check name is really a name here
.... exec "%s=value" % name
.... loc = locals()
.... del loc["name"]
.... del loc["value"]
.... return "%s = %d" % ("+".join(loc.keys()), sum(loc.values()))
....'a+c+b+y+x = 36'

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top