views:

595

answers:

5

I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.

Can you recommend any methods or packages that would make this easy?

I'm also not opposed to exporting the data in, for instance, csv format and loading it into another program if that would be easier.

Edit:

Tried CairoPlot:

>>> data = [(10, 0), (11, 1), (12.5, 0), (15, 1)]
>>> def fn(t):
...     for d in data:
...             if t > d[0]:
...                     return d[1]
...     return data[-1][1]
...
>>> CairoPlot.function_plot( 'tester.png', data, 500, 300, discrete = True, h_bounds=( data[0][0],data[-1][0]), step = 1 )

This pinned my CPU at 100% for more than 10 minutes and was steadily eating memory. I killed it before it used up all of swap. Am I doing something wrong or is CairoPlot just broken?

Further edit:

I now have something more workable using CairoPlot, based loosely on the above code. However, it's not perfect because of the resolution: I may need up to tens of nanoseconds (1e-8) resolution in order to catch some of the shorter pulses. For a multi-second graph, this takes a very long time with this method.

+2  A: 

I haven't use it myself, but perhaps Cairo Plot is worth taking a look at.

bromfiets
+1  A: 

you may try using CairoPlot:

import CairoPlot

#the data list stands for your low-to-high (1) and high-to-low (0) data
data = lambda x : [0,0,1,1,0,0,1][x]
CairoPlot.function_plot( 'Up_and_Down', data, 500, 300, discrete = True, x_bounds=( 0,len(data) - 1 ), step = 1 )

For more information, check CairoPlot

Edit:

I didn't understand your function fn(t) here. The idea of the function_plot is to plot a function not a vector.

To plot those points, you could use function_plot on this way:

#notice I have split your data into two different vectors,
#one for x axis and the other one for y axis
x_data = [10, 11, 12.5, 15]
y_data = [0, 1, 0, 1]

def get_data( i ):
    if i in x_data :
        return y_data[x_data.index(i)]
    else :
        return 0

CairoPlot.function_plot( 'Up_and_Down', get_data, 500, 300, discrete = True, x_bounds=( 0,20 ), step = 0.5 )

I guess that will work

For the 100% pinning CPU, that shouldn't happen... I'll take a look at it later today. Thanks for pointing it \o_

Rodrigo
By the way, I noticed that the docstring for function_plot claims you can pass a dict of {"label":fn()} into it to get multiple labelled plots. But, when I do this, it punks out complaining that I didn't give it a callable.
Jorenko
Also, looks like you're the maintainer for CairoPlot? You may be interested to know that it breaks in python 2.4 because max only added kwargs support in 2.5.
Jorenko
@Jorenko man, are you using the trunk version or the 1.1 version? If it's the trunk, dictionaries of functions should be working (and I'll have to take a look). If it's v1.1, the docstring must be wrong.
Rodrigo
@Jorenko Oh, and yes, i'm the maintainer. And I was aware of that 2.4 bug. Must find a way to fix it yet...
Rodrigo
A: 

http://bitworking.org/projects/sparklines/ provides a tiny graph for you.

joeforker
A: 

GnuPlot is a the old reliable answer here, easy graphing with lots of options. I believe there are python bindings but it's probably easier to export your data and run it through regular gnuplot. Here's an ancient quick start doc for it.

I'm also using matplotlib with great success for larger data sizes.

Parand
A: 

Matplotlib might work. Take a look at this strip chart demo.

alif