pyqtgraph:如何在00:00之前不显示时间序列(使用AxisItem)

时间:2015-04-10 14:57:39

标签: python datetime time-series pyside pyqtgraph

如何显示从00:00开始的时间轴,并且在00:00之前不显示时间轴?图表将显示从游标读取的实时数据。它将从00:00(数据到达的时间)开始绘制图表最右侧的数据,并在数据到达时向左滑动。所以我想在00:00之前摆脱时间轴值? 我感谢您的所有建议。

from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
from PySide.QtCore import QTime, QTimer
from collections import deque

t = QTime()
t.start()
data = deque()
class TimeAxisItem(pg.AxisItem):
def tickStrings(self, values, scale, spacing):
    return [QTime().addMSecs(value).toString('mm:ss') for value in values]

app = QtGui.QApplication([])
win = pg.GraphicsWindow()
win.resize(1000,600)
print type(win)
axis = TimeAxisItem('bottom')
plot = win.addPlot(title='Timed data',axisItems={'bottom':axis},enableMenu=False)
curve = plot.plot()

now = 0
timeStart = -15000
minX =-15000
i = 0
def update():
global i, plot, curve, data,minX,now,timeStart
time = t.elapsed()
data.append({'x': time, 'y': np.random.randint(0, 100)})
timeStart += 1
x = [item['x'] for item in data]
y = [item['y'] for item in data]
if i == 0:
            difference = x[-1]
            i = 1
else:
            difference = x[-1] - x[-2]
minX += difference
plot.setXRange(minX,x[-1])
curve.setData(x=x, y=y)
tmr = QTimer()
tmr.timeout.connect(update)
tmr.start(100)
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
    QtGui.QApplication.instance().exec_()

1 个答案:

答案 0 :(得分:0)

您是否可以为小于0的任何内容提供空白字符串?

def tickStrings(self, values, scale, spacing):
    return ['' if value < 0 else 
            QTime().addMSecs(value).toString('mm:ss') for value in values]