Я хочу построить временной ряд с помощью 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