123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/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()
|