python中的快速脏条带图?

python中的快速脏条带图?,python,graphing,stripchart,Python,Graphing,Stripchart,我有一些python代码,它每隔一段时间接收一条消息,其中包含一个时间戳和一个边缘转换(从低到高,或从高到低)。我想在条形图上绘制每个转换,以便用最少的工作量快速、直观地显示数字波形 您能推荐一些方法或软件包来简化这一过程吗 我也不反对以csv格式导出数据并将其加载到另一个程序中,如果这样做更容易的话 编辑: 试过的CairoPlot: >>> data = [(10, 0), (11, 1), (12.5, 0), (15, 1)] >>> def fn(t

我有一些python代码,它每隔一段时间接收一条消息,其中包含一个时间戳和一个边缘转换(从低到高,或从高到低)。我想在条形图上绘制每个转换,以便用最少的工作量快速、直观地显示数字波形

您能推荐一些方法或软件包来简化这一过程吗

我也不反对以csv格式导出数据并将其加载到另一个程序中,如果这样做更容易的话

编辑:

试过的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 )
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 )
这使我的CPU在100%的状态下工作了10多分钟,并且一直在消耗内存。我在它用完所有的钱之前就把它杀了。是我做错了什么,还是CairoPlot刚刚坏了

进一步编辑:


我现在有了一些更可行的使用CairoPlot的东西,松散地基于上面的代码。然而,由于分辨率的原因,它并不完美:我可能需要高达数十纳秒(1e-8)的分辨率才能捕捉到一些较短的脉冲。对于多秒图形,使用此方法需要很长时间。

我自己没有使用过它,但可能值得一看。

您可以尝试使用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 )
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 )
有关更多信息,请查看

编辑:

我不明白这里的函数fn(t)。函数图的思想是绘制一个函数,而不是一个向量

要绘制这些点,可以通过以下方式使用函数_plot:

#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 )
我想那会有用的

对于100%固定CPU,这不应该发生。。。今天晚些时候我会看一看。谢谢你指点 \o_

为您提供了一个很小的图形。

是一个古老的可靠答案,可以通过许多选项轻松绘制。我相信有python绑定,但是导出数据并通过常规gnuplot运行数据可能更容易。这是一个古老的故事


我还非常成功地使用了更大的数据量。

可能有用。看看这个。

有关仅使用tkinter(无需外部软件包)的实时条形图应用程序,请参阅


如果我理解您的问题,您将实时接收具有纳秒分辨率时间戳的消息,但您不希望每秒看到10^9条消息。如果平均消息速率很低(每秒100条消息或更少),我只需忽略时间戳,一次一条消息地绘制转换。如果图形的时间刻度为每像素10毫秒,则在40毫秒内将绘制4个过渡,但至少您不会错过看到发生的情况。

好的,编辑我的答案以尝试使用您的数据,希望它现在可以工作!所以,你需要精确到纳秒,并且想要绘制秒数的数据?这肯定是一个问题,对于1,你将得到1e9分。。。我想我很难理解你想在这张图上显示的是什么……我并不在乎有完全准确的、视觉上可辨别的纳秒分辨率,而是绘图算法需要在该分辨率下检查新的边,这样它就不会错过短脉冲,比如:[(10.0,0),(10.00000001,1),(10.00000002,0),(11.0,1),(12.0,0)]对于我最后一条评论中的数据,我希望看到一个非常短的脉冲,它实际上只是一条1像素的垂直线,在10。顺便说一句,我注意到function_plot的docstring声明您可以将{“label”:fn()}的dict传递到其中,以获得多个带标签的绘图。但是,当我这么做的时候,它会抱怨我没有给它一个callable。而且,看起来你是CairoPlot的维护者?您可能有兴趣知道它在Python2.4中中断了,因为max在2.5中只添加了kwargs支持。@Jorenko man,您使用的是trunk版本还是1.1版本?如果是主干,函数字典应该可以使用(我必须看一看)。如果是v1.1,文档字符串一定是错的。@Jorenko哦,是的,我是维护者。我意识到了2.4的错误。必须想办法解决它。。。
#simple stripchart using pygame
import pygame, math, random                   
white=(255,255,255)                             #define colors                      
red=(255,0,0)
pygame.init()                                   #initialize pygame
width=1000
height=200
size=[width,height]                             #select window size
screen=pygame.display.set_mode(size)            #create screen
pygame.display.set_caption("Python Strip Chart")
clock=pygame.time.Clock()
data=[]
for x in range (0,width+1):
        data.append([x,100])

# -------- Event Loop -----------
while (not pygame.event.peek(pygame.QUIT)):     #user closed window
        for x in range (0,width):
                data[x][1]=data[x+1][1]       #move points to the left
        t=pygame.time.get_ticks()            #run time in milliseconds
        noise=random.randint(-10,10)         #create random noise
        data[width][1]=100.-50.*math.sin(t/200.) +noise #new value
        screen.fill(white)                         #erase the old line
        pygame.draw.lines(screen, red, 0,data,3)   #draw a new line
        clock.tick(150)                            #regulate speed
        pygame.display.flip()                  #display the new screen
pygame.quit ()                                #exit if event loop ends