python绘制时间轴_MatPlotLib动态时间轴

本文提供了一个通用的Python示例,使用Matplotlib库动态地绘制时间轴。通过创建`Monitor`和`StreamingDisplay`类,实现了数据的捕获和更新。示例中,数据点根据需求不断更新,展示了如何在图表上实时反映变化的数据流。
摘要由CSDN通过智能技术生成

因为我不知道你流的是什么,我写了一个通用的例子,它可以帮助你解决你的问题。在from pylab import *

import matplotlib.animation as animation

class Monitor(object):

""" This is supposed to be the class that will capture the data from

whatever you are doing.

"""

def __init__(self,N):

self._t = linspace(0,100,N)

self._data = self._t*0

def captureNewDataPoint(self):

""" The function that should be modified to capture the data

according to your needs

"""

return 2.0*rand()-1.0

def updataData(self):

while True:

self._data[:] = roll(self._data,-1)

self._data[-1] = self.captureNewDataPoint()

yield self._data

class StreamingDisplay(object):

def __init__(self):

self._fig = figure()

self._ax = self._fig.add_subplot(111)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值