In my project with raspberry pi and pyqtgraph. I am trying to plot system 
time on x axis which* works great on windows but not on raspbian*. Instead 
of showing system time and date it starts updating x axis from 01/01/1970 
01:00:00. I am confused how to proceed. heres my code

    
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



I'd be thankful if someone can help me with this as this problem is 
bothering me since two days without any solution

Kind regards,
Ajay

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/3e73cb2d-b210-4b33-89de-fe5bf993e5f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to