我在python3.6.2(32位)和windows10上使用PyQtGraph'0.9.8+gd627e39。在
我的目标是用显示日期时间的X轴绘制实时数据。在
Time Value
datetime.datetime(2018, 3, 1, 9, 36, 50, 136415) 10
datetime.datetime(2018, 3, 1, 9, 36, 51, 330912) 9
datetime.datetime(2018, 3, 1, 9, 36, 51, 382815) 12
datetime.datetime(2018, 3, 1, 9, 36, 52, 928818) 11
...
我查了相关的问题,比如
https://gist.github.com/friendzis/4e98ebe2cf29c0c2c232,pyqtgraph, plotting time series,但我仍然很难掌握如何使用DateAxisItem
我试着用这个模块做一个简单的代码
^{pr2}$但它显示一条错误消息,根本不显示它的X轴。在
Traceback (most recent call last):
File "<tmp 10>", line 19, in <module>
graph.plot(x=list_x, y=list_y, pen=None, symbol='o')
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\PlotItem\PlotItem.py", line 636, in plot
item = PlotDataItem(*args, **kargs)
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\PlotDataItem.py", line 177, in __init__
self.setData(*args, **kargs)
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\PlotDataItem.py", line 461, in setData
self.updateItems()
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\PlotDataItem.py", line 493, in updateItems
self.scatter.setData(x=x, y=y, **scatterArgs)
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\ScatterPlotItem.py", line 308, in setData
self.addPoints(*args, **kargs)
File "d:\python36-32\lib\site-packages\pyqtgraph\graphicsItems\ScatterPlotItem.py", line 388, in addPoints
newData['x'] = kargs['x']
TypeError: float() argument must be a string or a number, not 'datetime.datetime'
是因为DateAxisItem
不支持日期时间吗?如果我能通过查看模块的代码来理解它,那就太好了,但是不幸的是,我的技能并不好。在
如果有人能告诉我如何使用这个模块和一些简单的数据,我将不胜感激。在
基于前面的answer,pyqtgraph中的绘图只接受数值类型的数据,因此必须转换它,在本例中,我们使用
timestamp()
,然后在自定义的AxisItem
中,我们将其转换为字符串,并借助fromtimestamp
来显示它。在相关问题 更多 >
编程相关推荐