【问题标题】:pyqtgraph, plotting time seriespyqtgraph,绘制时间序列
【发布时间】:2015-04-02 11:30:58
【问题描述】:

我正在尝试用 pyqtgraph 绘制时间序列。我读过thisthisthis。但我不确定如何正确使用它。

我的情节是一个情节小部件,我这样使用它:

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'

【问题讨论】:

    标签: python datetime plot pyqtgraph


    【解决方案1】:

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

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

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

    谢谢!

    【讨论】:

    • 我希望我可以,但我既不记得我的密码也不记得我提出问题的帐户的电子邮件。
    猜你喜欢
    • 2014-06-02
    • 2015-08-10
    • 2017-09-28
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多