我查看了这个版本的pyqtgraph
git clone https://github.com/3rdcycle/pyqtgraph.git
git checkout origin/date-axis-item
pip uninstall pyqtgraph
python setup.py install
然后我运行这个程序。它看起来运行正常,除了我的x轴时间戳进入和退出视图而我没有做任何事情。不确定这是否是此程序或DateAxisItem
中的错误。此外,毫秒总是100的倍数。例如,我看到00:00:00:900,00:00:01:200,但从不00:00:00:042?
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 21:09:44 2015
@author: idf
"""
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(maxlen=20)
class TimeAxisItem(pg.DateAxisItem):
def __init__(self, *args, **kwargs):
super(TimeAxisItem, self).__init__(*args, **kwargs)
def tickStrings(self, values, scale, spacing):
return [QTime().addMSecs(value).toString('hh:mm:ss.zzz') for value in values]
app = QtGui.QApplication([])
win = pg.GraphicsWindow(title="Basic time-plotting examples")
win.resize(1000,600)
plot = win.addPlot(title='Timed data', axisItems={'bottom': TimeAxisItem(orientation='bottom')})
curve = plot.plot()
def update():
global plot, curve, data
data.append({'x': t.elapsed(), 'y': np.random.randint(0, 100)})
x = [item['x'] for item in data]
y = [item['y'] for item in data]
curve.setData(x=x, y=y)
tmr = QTimer()
tmr.timeout.connect(update)
tmr.start(800)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
答案 0 :(得分:0)
我不确定您的DateAxisItem会发生什么。如您所知,它尚未合并到PyQtGraph的主要开发分支中。但是,对于您的特定应用程序,从头开始并定义您自己的TimeAxisItem可能更容易?如果从以下代码开始,将缺少哪些功能?
class TimeAxisItem(AxisItem):
def __init__(self, orientation, **kwargs):
super().__init__(orientation, **kwargs)
def tickStrings(self, values, scale, spacing):
return [self.get_tick(v, spacing) for v in values]
def get_tick(self, ts, spacing):
dt = datetime.datetime.fromtimestamp(ts)
# Here you can decide on the accuracy of the time data
# displayed depending on the spacing.
if spacing > 60:
return "%02d:%02d" % (dt.hour, dt.minute)
else:
return "%02d:%02d:%02d" % (dt.hour, dt.minute, dt.second)