2

我有一些 python 代码经常接收包含时间戳和边缘转换的消息,无论是从低到高还是从高到低。我想在条形图上绘制每个转换,以便以最少的努力快速而肮脏地可视化数字波形。

您能推荐任何可以简化此操作的方法或软件包吗?

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

编辑:

尝试开罗情节:

>>> 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 )

这将我的 CPU 固定在 100% 的时间超过 10 分钟,并且一直在消耗内存。我在它用完所有交换之前杀死了它。我做错了什么还是 CairoPlot 刚刚坏了?

进一步编辑:

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

4

7 回答 7

2

Matplotlib可能会工作。看看这个带状图表演示

于 2009-02-17T19:04:22.747 回答
2

我自己没用过,但也许Cairo Plot值得一看。

于 2009-02-17T14:35:19.680 回答
1

您可以尝试使用 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 )

有关更多信息,请查看CairoPlot

编辑:

我不明白你的函数 fn(t) 在这里。function_plot 的想法是绘制函数而不是向量。

要绘制这些点,您可以这样使用 function_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_

于 2009-02-17T14:52:53.023 回答
1
#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
于 2016-01-10T05:49:55.547 回答
0

http://bitworking.org/projects/sparklines/为您提供了一个小图表。

于 2009-02-17T16:07:12.890 回答
0

GnuPlot是一个古老的可靠答案,带有很多选项的简单图形。我相信有 python 绑定,但导出数据并通过常规 gnuplot 运行它可能更容易。这是一个古老的快速入门文档

我还在使用matplotlib处理更大的数据量时取得了巨大的成功。

于 2009-02-17T16:17:38.123 回答
0

对于仅使用 tkinter(不需要外部包)的实时条形图应用程序,请参阅What is the best real time plotting widget for wxPython? .

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

于 2011-09-30T02:44:04.523 回答