-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyqtplot02.py
executable file
·50 lines (33 loc) · 1.43 KB
/
pyqtplot02.py
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
#!/usr/bin/env python
# File: pyqtplot02.py
# Name: D.Saravanan
# Date: 08/07/2023
""" Script to create plot using the PlotWidget in PyQtGraph """
import sys
import pyqtgraph as pg
from PyQt6 import QtCore, QtWidgets
class MainWindow(QtWidgets.QMainWindow):
"""Subclass of QMainWindow to customize application's main window."""
def __init__(self, hour, temperature):
super().__init__()
# set the size parameters (width, height) pixels
self.setFixedSize(QtCore.QSize(640, 480))
# set the central widget of the window
self.graphWidget = pg.PlotWidget()
self.setCentralWidget(self.graphWidget)
# set the background color using hex notation #121317 as string
self.graphWidget.setBackground("#121317")
# plot data: x, y values
self.graphWidget.plot(hour, temperature)
def main():
"""Need one (and only one) QApplication instance per application.
Pass in sys.argv to allow command line arguments for the application.
If no command line arguments than QApplication([]) is required."""
app = QtWidgets.QApplication(sys.argv)
hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
window = MainWindow(hour, temperature) # an instance of the class MainWindow
window.show() # windows are hidden by default
sys.exit(app.exec()) # start the event loop
if __name__ == "__main__":
main()