pyqtgraph,绘制时间序列

pyqtgraph, plotting time series

我正在尝试使用 pyqtgraph 绘制时间序列。我读过 this, this and 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')})

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

然后我尝试使用 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'

我终于解决了我的问题,很简单。

我只需要这样初始化我的绘图小部件:

    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数据作为时间戳数组。

谢谢!