[英]pyqtgraph, plotting time series
I'am trying to plot time serie with pyqtgraph. 我正在尝试用pyqtgraph绘制时间序列。 I've read this , this and this . 我已经看过这个 , 这个和这个 。 But i'am not sure how to correctly use it. 但是我不确定如何正确使用它。
My plot is a plot widget, and i use it this way: 我的情节是情节小部件,我以这种方式使用它:
graph.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})
where TimeAxisItem is defined like this: TimeAxisItem的定义如下:
class TimeAxisItem(pg.AxisItem):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def tickStrings(self, values, scale, spacing):
# PySide's QTime() initialiser fails miserably and dismisses args/kwargs
return [useful_values_dict['useful_data']['data']['ISO_dates']]
where ISO_dates is a list of date and time in ISO format 其中ISO_dates是ISO格式的日期和时间列表
I've also tried this: 我也尝试过这个:
graph.plotItem.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})
but with no effects (axis strings are stil numbers). 但没有效果(轴字符串是Stil数字)。
Then i tried to use the DateTimeAxis.py, this way: 然后,我尝试通过以下方式使用DateTimeAxis.py:
date_axis = pg.DateAxisItem('bottom', pen=None, linkView=None, parent=None, maxTickLength=-1, showValues=True)
date_axis.tickStrings(useful_values_dict['useful_data']['data']['timestamp_dates'],1, 1)
but i get an error: 但我得到一个错误:
File "C:\Python34\lib\site-packages\pyqtgraph\graphicsItems\DateAxisItem.py", line 161, in tickStrings
format_strings.append(x.strftime(tick_spec.format))
AttributeError: 'NoneType' object has no attribute 'format'
I finally solved my problem, it was quite easy. 我终于解决了我的问题,这很容易。
I just needed to initialize my plot widget that way: 我只需要以这种方式初始化我的绘图小部件:
date_axis = pg.graphicsItems.DateAxisItem.DateAxisItem(orientation = 'bottom')
self.graph = pg.PlotWidget(axisItems = {'bottom': date_axis})
and plot my data that way: 并以这种方式绘制我的数据:
graph.plot(x = useful_values_dict['useful_data']['data']['timestamp_dates'],
y = useful_values_dict['useful_data']['data'][raw_header],
pen=pg.mkPen(color=colors[count],width=1,style=QtCore.Qt.SolidLine))
with x data as an array of timestamp. 使用x数据作为时间戳数组。
Thanks ! 谢谢 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.