1
我檢查了這個版本pyqtgraph的DateAxisItem有時變得不可見
的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_()
您正在定義您自己的AxisItem。爲什麼你需要從DateAxisItem繼承? –
因爲我想控制小數秒部分顯示的小數位數。否則,它將長達6位小數。 – Ivan