Real-time graphs

G

Guest

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

TIA
Stephen
 
D

Doug Holton

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

Unfortunately there is not anything designed specifically for
real-time graphs in python. You could create a custom control.

My suggestion is to use a Timer (like wx.Timer in wxpython) set to a
particular "frame rate" - how many times the graph should be refreshed
per second. Everytime it fires it updates the graph (if it is a
scrolling plot, or else if the data has changed). Meanwhile in a
background thread your time-stamped data points are collected, perhaps
into two lists. If it is a scrolling plot you could discard (or log)
data that is old.
 
S

snrkiwi-lists

This is pretty much my plan (or to use an observer pattern). But I was
wondering if anyone had used any particular graphing package to
generate these types of graphs? I wouldn't think that driving gnuplot
in the background would be an efficient approach, for example.
 
L

Lucas Raab

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

TIA
Stephen

You could make a Tkinter canvas and set it up to display the graph and
update it every second or however long you wish.
 
S

SeeBelow

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

Here is something I wrote a few years ago that simulates a strip chart
recorder. Execute plotter.py; it will import from model.py.

Mitchell Timin

--
"Many are stubborn in pursuit of the path they have chosen, few in
pursuit of the goal." - Friedrich Nietzsche

http://annevolve.sourceforge.net is what I'm into nowadays.
# model.py - components for dynamic models
# by Mitchell Timin, 1999

from random import gauss

class delay:
"Pure time delay of a time sequence, like a tape loop"
def __init__(self, steps):
"initialize a new delaying object - argument is number of steps"
self.hist = []
for i in range(steps):
self.hist.append(0.0)
def lag(self, input):
" Object.lag(input) returns an earlier value of input."
self.hist.append(input)
return(self.hist.pop(0))

class generate:
def __init__(self):
self.X = 10.0
self.Y = 10.0
self.A = -0.2
self.B = -0.15
self.C = +0.12

def next(self):
dX = self.A*self.X + self.B*self.Y + gauss(0.0, .05)
dY = .4*self.X + self.C*self.Y
self.X = self.X + dX
self.Y = self.Y + dY
return(self.X, self.Y)

def modA(self, cont, oldcont):
self.A = self.A * (100 + cont - oldcont)/98.0
def modB(self, cont, oldcont):
self.B = self.B * (100 + cont - oldcont)/98.0
def modC(self, cont, oldcont):
self.C = self.C * (100 + cont - oldcont)/98.0

# Continuous plotting & control of a dynamic model
# by Mitchell Timin, 1999

# These are Python standard items:
from Tkinter import *
from time import sleep
from thread import start_new_thread, exit

# This is the dynamic model:
from model import generate
model = generate()

# This section sets up the graphics display and controls:
wide = 810 ; high = 560 # pixel dimensions of canvas
Halt = 0
def halt():
"used by PAUSE button to toggle Halt variable"
global Halt
if(Halt):
Halt = 0
else:
Halt = 1
root=Tk()
root.protocol("WM_DELETE_WINDOW", root.destroy)
frame = Frame(root)
frame.pack()
button = Button(frame, text="QUIT", fg="red", command=frame.quit)
button.pack(side=LEFT)
butt = Button(frame, text="PAUSE", fg="blue", command=halt)
butt.pack(side=LEFT)
but = Button(frame, text="RESTART", fg="green", command=model.__init__)
but.pack(side=LEFT)
scale = Scale(root)
scale.pack(side=LEFT)
scal = Scale(root)
scal.pack(side=LEFT)
sca = Scale(root)
sca.pack(side=LEFT)
canvas=Canvas(root,width=wide,height=high)
canvas.pack()

# A sequence of short line segments will be drawn on the canvas.
# This code gets ready for that:
offset = 5 # just a few pixels away from the edge
dx = 20 # stepsize in horizontal direction
stime = .15 # real time delay between segments (seconds)

# Y and Z are the model's dependent variables, unscaled.
# ypix and zpix are the scale values in pixels.
# xpix represents time, in pixels horizontally.
yscale = zscale = 10.0


def nexpix(x):
"returns a tuple of the pixel values representing the models output"
Y, Z = model.next()
ypix = int((high/2)-Y*yscale)
zpix = int((high/2)-Z*zscale)
return x+dx, ypix, zpix

# compute the starting points:
xs, ys, zs = nexpix(offset-dx)

def draw(stime):
"Repeatedly draws line segments, calling the model for values:"
global xs,ys,zs,dx
# get the user control values:
pc1, pc2, pc3 = scale.get(), scal.get(), sca.get()
while 1:
sleep(stime)
while(Halt):
sleep(.1)
# get the user control values:
c1, c2, c3 = scale.get(), scal.get(), sca.get()
if(c1 != pc1):
model.modA(c1, pc1)
pc1 = c1
if(c2 != pc2):
model.modB(c2, pc2)
pc2 = c2
if(c3 != pc3):
model.modC(c3, pc3)
pc3= c3
#update the model, then draw a line segment for each variable:
xf, yf, zf = nexpix(xs)
l1 = canvas.create_line(xs, ys, xf, yf, width=2,fill="blue")
l2 = canvas.create_line(xs, zs, xf, zf, width=2,fill="green")
# save the endpoints; they will become the starting points:
xs,ys,zs = xf, yf, zf
# This is to delete the older, offscreen, line segments:
if l1 > 100 and l2 > 100:
canvas.delete(l1-100);canvas.delete(l2-100)
if xs >= wide:
canvas.move(ALL,-dx,0)
xs = xs - dx

start_new_thread(draw,(stime,))

root.mainloop()
 
G

Graham Dumpleton

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

TIA
Stephen

Where I once worked, they used Blt for Tkinter under the Pmw toolkit for Python.

See:

http://pmw.sourceforge.net
http://heim.ifi.uio.no/~hpl/Pmw.Blt/doc

The latter site has some good illustrative examples.
 
G

gsm

look at http://www.advsofteng.com/

ChartDirector is free and really good, best package that I know for
graphing, also provides you with a base livbrary for designing your own, its
engine is very small and design for the web etc, its output is exceptional
in terms of font quality etc

supports NET, ASP, COM, VB, JSP,Java, PHP, Perl, Python, C++
 
K

Kevin Dahlhausen

It looks sharp, but the free version has watermarks and is
distributable only in free software.
 
S

snrkiwi-lists

Thanks for the info, all. It is certainly helping! Collating it all,
and given our current setup and requirements (not web based, no Java,
wxPython, lots of real time graphs per screen, Mac OS X and Linux), it
seems only a couple of possibilities stand out.

- VPython
- matplotlib

Having said that, neither of these appeared to come with examples with
wxPython, but I guess you can't ask for everything! :)

Does anyone have any direct experience with either of these inside of
wxPython? It appears that matplotlib will directly work with wxPython,
not so for VPython?

If we were using Tkinter, we might have other options apparently. I
also have noticed a couple of other packages that no-one noted here

- DISLIN
- pgplot

Does anyone have any experience with these in a wxPython setting?

TIA
 
T

Tom

I do lab instrument programming - moving stages, polling sensors &
controlling instruments. My GUIs have lots of visual feedback - live
charts, buttons, indicators, meters, gauges. I use wxPython for the
GUI framework, python+numeric for lots of the number
crunching/analysis, and swig for wrapping hardware drivers/dlls. For
the gauge, plot, and button widgets, I use the national instruments
"measurement studio" activex objects through wxPython activex hosting.
This works well and was very easy - esp. if you use the CVS BOA
constructor IDE. Of course it requires that you buy the NI
measurement studio for Visual basic. I already had it because I used
to use labview/labwindows for this stuff. It will cost you like $800
for just the widgets (no labview) if I recall correctly.

There are many other commercial visual basic/activex widget sets for
lab instrumentation/process monitoring. Take your pick. Some will be
cheaper/faster/better I'm sure.

the disadvantage of this approach is that 1) costs money 2) the vendor
will probably only offer VB support, not Python 3) windows only. None
of these are a problem for me, since most hardware drivers are windows
only anyway.

Some day some one will make a great lightweight plotting widget that
will drop right into wxpython no problem. I might even do this. But
it hasn't happened yet. THere are a hundred plotting packages that
shoehorn into wxpython - scipy/chaco, NCARgraphics, and a lot more
I've tried and forgotten. They are all too slow, too immature, or too
much trouble to use. But wxPython works very well with Activex
widgets. They look really good, are fast, and the wrapped widget
classes are very pythonic to program.
 
F

Fernando Perez

I've trolled the lists, FAQs, and Net as a whole, but
can't find anything definitive to answer this.

We're looking for real-time graph capability (bar,
line, etc), so that we can display telemetry from a
robot system. There are a bunch of packages out
there, but many seem to provide only static graphs
(e.g. for scientific, financial data, etc). Does
anyone currently display real-time telemetry using
Python? Can anyone provide any suggestions?

I suspect matplotlib will be your best choice, but you might also check out
HippoDraw (google for it). It's Qt-based, designed to read instrument data at
SLAC (Stanford Linear Accelerator). I've seen demos of it, and it looked very
good.

Best,

f
 

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,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top