x轴日期和时间显示01/01/1970 01:00:00而不是当前时间

时间:2016-09-30 09:33:17

标签: python raspberry-pi pyqtgraph

在我的项目中使用raspberry pi和pyqtgraph。我试图在x轴上绘制系统时间,这在窗户上很好用,但在raspbian上却不行。它不是显示系统时间和日期,而是从01/01/1970 01:00:00开始更新x轴。我很困惑如何继续。继承我的代码

import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph.exporters
import time

app = QtGui.QApplication([])

pg.setConfigOption('background', 'w')


win = pg.GraphicsWindow(title="Live Graphs")  # creating a window for graphs
win.resize(1920, 720)
win.setWindowTitle('Condition Monitoring')   # Setting up the title
win.ci.setBorder((50, 50, 100))

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("%d-%m-%Y\n %H:%M:%S", time.localtime(x)))    # time_t --> time.struct_time
            except ValueError:  # Windows can't handle dates before 1970
                strns.append('')
        return strns

axis1 = CAxisTime(orientation='bottom')

p1 = win.addPlot(axisItems={'bottom': axis1}, title = '<b>Humidity')  # creating the plot for humidity
curve1 = p1.plot(pen = '#00A3E0')  # setting up the curve and the color
humC1 = [] # an empty list for humidity values
times1 = [] # an empty time list 
indx1 = 0   # variable set to zero
hum = BrickletHumidity(UIDhum, ipcon) # Humidity Bricklet 

def updateSensorHum():
    global curve1,tempC1, indx1, times1, hum, t0

    humidity = hum.get_humidity() # get the value of the relative humidity from humidity bricklet 

    dataArray1=str(humidity/10).split(',')  # creating a data array and splitting the values  
    temp1 = float(dataArray1[0]) # creating a float object of data array
    humC1.append(temp1) # appending the humidity values
    times1.append(time.time())   # appending the time values

    if (indx1 > 250):  # if indx1 > 300
        humC1.pop(0)    # start eliminating the 1st value stored in the array
        times1.pop(0) # start eliminating the time from the x axis
    indx1 = indx1 + 1   # increase index by 1
    curve1.setData(humC1) # drawing the curve humidity vs time
    app.processEvents() #process the events in the created app

def update():
    updateSensorHum() # update Humidity Sensor

    exporter = pg.exporters.ImageExporter(win.scene()) # export the image exporter library
    exporter.export('ConditionMonitoring.png') # export the file as SVG

timer = pg.QtCore.QTimer() # import timer library
timer.timeout.connect(update) # set the connection with the function to be update
timer.start(999) # start the timer

如果有人可以帮助我,我会感激不尽,因为这个问题困扰了我两天没有任何解决方案

亲切的问候, 阿贾伊

0 个答案:

没有答案