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
| import sys import numpy as np import pyqtgraph as pg from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget from PyQt5 import QtCore
class MainWindow(QMainWindow): def __init__(self): super().__init__()
self.setWindowTitle("Curve Plot") self.resize(800, 600)
main_layout = QVBoxLayout()
self.plot_widget = pg.GraphicsLayoutWidget()
main_layout.addWidget(self.plot_widget)
central_widget = QWidget() central_widget.setLayout(main_layout) self.setCentralWidget(central_widget)
def plot_curves(self, data): num_plots = len(data) rows = (num_plots + 2) // 3
self.plot_widget.clear()
for i, curve_data in enumerate(data): row = i // 3 col = i % 3
plot = self.plot_widget.addPlot(row=row, col=col) plot.plot(curve_data)
app = QApplication(sys.argv) window = MainWindow() window.show()
t = np.linspace(0, 10, 100) data = [np.sin(t), np.cos(t), np.tan(t), np.exp(-t), 1 / (t + 1)]
window.plot_curves(data)
sys.exit(app.exec_())
|