【问题标题】:pyqtgraph : how to plot time series (date and time on the x axis)?pyqtgraph:如何绘制时间序列(x 轴上的日期和时间)?
【发布时间】:2014-06-02 19:33:49
【问题描述】:

我想用 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

【问题讨论】:

标签: time-series pyqtgraph


【解决方案1】:

看看this gist。您可以修改 tickStrings() 以根据比例更改格式字符串

【讨论】:

  • 链接已失效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-29
  • 2021-10-14
  • 2015-08-13
  • 1970-01-01
  • 2021-05-18
  • 2019-04-22
相关资源
最近更新 更多