PyQtGraph
PyQtGraph is an open-source Python library for scientific graphics and GUI development, built on top of Qt and NumPy. It provides fast, interactive plotting for large datasets, signal/image processing, and sophisticated GUI elements, making it ideal for scientific and engineering applications. The current version is 0.14.0, and it maintains a relatively active release cadence with several minor and patch releases per year.
Warnings
- breaking The classes `MetaArray`, `MultiPlotItem`, and `MultiPlotWidget` have been removed.
- breaking Support for Python 3.8 and NumPy 1.20 has been dropped.
- breaking Minimum supported Qt versions have been increased to Qt5 5.15 and Qt6 6.2+.
- deprecated The `GraphicsObject::parentChanged` method has been deprecated.
- gotcha Forgetting to start the Qt event loop or calling `QApplication.exec_()` (or `exec()`) can lead to the GUI window appearing briefly and then closing, or not appearing at all.
Install
-
pip install pyqtgraph -
pip install pyqtgraph[PyQt6] -
pip install pyqtgraph[PySide6] -
pip install pyqtgraph[PyQt5] -
pip install pyqtgraph[PySide2]
Imports
- pyqtgraph
import pyqtgraph as pg
- QtWidgets, QtCore
from pyqtgraph.Qt import QtWidgets, QtCore
- mkQApp
app = pg.mkQApp('Your App Name')
Quickstart
import pyqtgraph as pg
from pyqtgraph.Qt import QtWidgets
# Always start by creating a QApplication
app = pg.mkQApp("PyQtGraph Quickstart")
# Create a GraphicsLayoutWidget (a window to hold plots)
win = pg.GraphicsLayoutWidget(show=True, title="Basic Plot")
win.resize(800, 500)
win.setWindowTitle('PyQtGraph Quickstart Example')
# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)
# Add a plot item to the window
p = win.addPlot(title="Simple Line Plot")
# Generate some data
data = [1, 5, 2, 4, 3, 8, 9, 1, 2, 3, 5]
# Plot the data
p.plot(data)
# Start the Qt event loop if running as a script
if __name__ == '__main__':
QtWidgets.QApplication.instance().exec_()