pyqtplot02.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # File: pyqtplot02.py
  3. # Name: D.Saravanan
  4. # Date: 08/07/2023
  5. """ Script to create plot using the PlotWidget in PyQtGraph """
  6. import sys
  7. import pyqtgraph as pg
  8. from PyQt6 import QtCore, QtWidgets
  9. class MainWindow(QtWidgets.QMainWindow):
  10. """Subclass of QMainWindow to customize application's main window."""
  11. def __init__(self, hour, temperature):
  12. super().__init__()
  13. # set the size parameters (width, height) pixels
  14. self.setFixedSize(QtCore.QSize(640, 480))
  15. # set the central widget of the window
  16. self.graphWidget = pg.PlotWidget()
  17. self.setCentralWidget(self.graphWidget)
  18. # set the background color using hex notation #121317 as string
  19. self.graphWidget.setBackground("#121317")
  20. # plot data: x, y values
  21. self.graphWidget.plot(hour, temperature)
  22. def main():
  23. """Need one (and only one) QApplication instance per application.
  24. Pass in sys.argv to allow command line arguments for the application.
  25. If no command line arguments than QApplication([]) is required."""
  26. app = QtWidgets.QApplication(sys.argv)
  27. hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  28. temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
  29. window = MainWindow(hour, temperature) # an instance of the class MainWindow
  30. window.show() # windows are hidden by default
  31. sys.exit(app.exec()) # start the event loop
  32. if __name__ == "__main__":
  33. main()