pyqtgraph,绘制时间序列 - python

我正在尝试用pyqtgraph绘制时间序列。我已经读过this,this和this。但是我不确定如何正确使用它。

我的情节是情节小部件,我以这种方式使用它:

graph.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})

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']]

其中ISO_dates是ISO格式的日期和时间列表

我也尝试过这个:

graph.plotItem.plot(aerosol_data, pen=pg.mkPen(color=colors[count], width=1, style=QtCore.Qt.SolidLine), axisItems={'bottom': TimeAxisItem(orientation='bottom')})

但没有效果(轴字符串是Stil数字)。

然后,我尝试通过以下方式使用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)

但我得到一个错误:

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'

python大神给出的解决方案

我终于解决了我的问题,这很容易。

我只需要以这种方式初始化我的绘图小部件:

    date_axis = pg.graphicsItems.DateAxisItem.DateAxisItem(orientation = 'bottom')
    self.graph = pg.PlotWidget(axisItems = {'bottom': date_axis})

并以这种方式绘制我的数据:

    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))

使用x数据作为时间戳数组。

谢谢 !