PyQtGraph:如何绘制时间序列(日期和时间在x轴上)?

3
我想使用pyqtgraph绘制时间序列,并在x轴上显示日期和/或时间刻度,但我找不到如何实现。
编辑1: 看起来我应该子类化AxisItem并重新实现tickStrings()。我会研究一下这个。
编辑2: 这是我如何子类化AxisItem的方法。文档展示了如何使用这个类。
from __future__ import print_function
from PySide.QtCore import *
from PySide.QtUiTools import *
from PySide.QtGui import *
import pyqtgraph as pg
import time

## Reimplements \c pyqtgraph.AxisItem to display time series.
# \code
# from caxistime import CAxisTime
# \# class definition here...
# self.__axisTime=CAxisTime(orientation='bottom')
# self.__plot=self.__glyPlot.addPlot(axisItems={'bottom': self.__axisTime}) # __plot : PlotItem
# \endcode
class CAxisTime(pg.AxisItem):
    ## Formats axis label to human readable time.
    # @param[in] values List of \c time_t.
    # @param[in] scale Not used.
    # @param[in] spacing Not used.
    def tickStrings(self, values, scale, spacing):
        strns = []
        for x in values:
            try:
                strns.append(time.strftime("%H:%M:%S", time.gmtime(x)))    # time_t --> time.struct_time
            except ValueError:  # Windows can't handle dates before 1970
                strns.append('')
        return strns

请查看此帖子 - shx2
1个回答

4

请查看此代码片段,可以修改tickStrings()函数中的格式字符串以根据比例缩放更改格式。


1
链接已失效。 - Griffin
奇怪,对我来说它仍然有效。@Griffin - ArduinoBen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接