PyQTGraph - X axis updating with minutes
Unsolved
Language Bindings
-
Hello to all,
here is a simple example of graph in PyQT4. Actual time is shown in simple GUI, special button is made for calling a graph with one curve which contains 61 points. Data is stored into buffers and updated when time is xx:xx:05. Data in buffer is mooved for one place to left (value of buffer[1] goes to buffer[0] and so on, in buffer[60] new value comes). When script is started X axis is built from 0 (left) to 60 (right) poits. What I would like to have on x axis instead of constants from 0 - 60 is actual time in minutes.
Is that even possible and how to do it?Vlado
import gui import sys import datetime from graph import simple_graph from PyQt4 import QtCore, QtGui from PyQt4.QtCore import QTimer if __name__ == "__main__": app = QtGui.QApplication(sys.argv) def time_show(): now = datetime.datetime.now() master.Time.setText(now.strftime("%H" + ":" + "%M" + ":" + "%S")) if ((now.strftime("%S")) == ("05")): master.update_buffer_minute() gui_master = gui.QtGui.QTabWidget() master = gui.Ui_Izbira() master.setupUi(gui_master) # Buttons master.pushButton_Graph.clicked.connect(simple_graph) # Timer - Trigers updating of time label every second timer = QTimer() timer.timeout.connect(time_show) timer.start(1000) gui_master.show() sys.exit(app.exec_())
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'test.ui' # # Created: Sun Apr 9 08:44:41 2017 # by: PyQt4 UI code generator 4.11.2 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui from Buffer_script import Buffer_Time_minute, Buffer_Zg from graph import OUT_Buffer_Time_minute, OUT_Buffer_Zg time_190 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] # year, month, day, hour, minuttes, seconds, week_day, up_6_7, up, down temp_160 = [0, 0, 0, 0, 0, 0, 0, 0, 0] # zg, sp, bo, so, pe, zu, szg, ssp, out try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) class Ui_Izbira(object): def setupUi(self, Izbira): Izbira.setObjectName(_fromUtf8("Izbira")) Izbira.resize(530, 363) Izbira.setWindowTitle(_fromUtf8("")) self.Mainpage = QtGui.QWidget() self.Mainpage.setObjectName(_fromUtf8("Mainpage")) self.Time = QtGui.QLineEdit(self.Mainpage) self.Time.setGeometry(QtCore.QRect(130, 70, 261, 71)) font = QtGui.QFont() font.setPointSize(47) font.setBold(False) font.setItalic(True) font.setWeight(50) self.Time.setFont(font) self.Time.setObjectName(_fromUtf8("Time")) self.pushButton_Graph = QtGui.QPushButton(self.Mainpage) self.pushButton_Graph.setGeometry(QtCore.QRect(130, 200, 261, 31)) self.pushButton_Graph.setObjectName(_fromUtf8("pushButton_Graph")) Izbira.addTab(self.Mainpage, _fromUtf8("")) self.retranslateUi(Izbira) Izbira.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(Izbira) def retranslateUi(self, Izbira): self.pushButton_Graph.setText(_translate("Izbira", "Graph", None)) Izbira.setTabText(Izbira.indexOf(self.Mainpage), _translate("Izbira", "Main page", None)) def update_buffer_minute(self): global time_190 a = time_190[4] Buffer_Time_minute(a, OUT_Buffer_Time_minute) b = 11 Buffer_Zg(b, OUT_Buffer_Zg) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) Izbira = QtGui.QTabWidget() ui = Ui_Izbira() ui.setupUi(Izbira) Izbira.show() sys.exit(app.exec_())
Buffer_script.py
def Buffer_Time_minute(IN_FiFo, OUT_Buffer_Time_minute): i = 0 for i in range(len(OUT_Buffer_Time_minute) - 1): OUT_Buffer_Time_minute[i] = OUT_Buffer_Time_minute[i + 1] i = i + 1 OUT_Buffer_Time_minute[60] = IN_FiFo def Buffer_Zg(IN_FiFo, OUT_Buffer_Zg): i = 0 for i in range(len(OUT_Buffer_Zg) - 1): OUT_Buffer_Zg[i] = OUT_Buffer_Zg[i + 1] i = i + 1 OUT_Buffer_Zg[60] = IN_FiFo
import pyqtgraph as pg OUT_Buffer_Zg = [5, 5, 5, 5, 5, 5, 5, 8, 8, 8, 8, 5, 5, 7, 7, 7, 7, 7, 9, 9, 9, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 0, 0, 0, 0, 0] OUT_Buffer_Time_minute = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60] def simple_graph(): H = pg.plot(OUT_Buffer_Time_minute, OUT_Buffer_Zg, pen='b') H.setTitle('Temperature Zgoraj Spodaj') H.addLegend() H.plot(OUT_Buffer_Time_minute, OUT_Buffer_Zg, pen='r', name='Zg') H.showGrid(True, True) H.setLabel('left', 'Temperatura', units='deg C') H.setLabel('bottom', 'Time', units='minute')