QCustomPlot PyQt5 绘图代码示例
from PyQt5.QtGui import QPen, QBrush, QColor
from QCustomPlot2 import *
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
import sys
import math
app = QApplication(sys.argv)
customPlot = QCustomPlot()
graph0 = customPlot.addGraph()
graph0.setPen(QPen(Qt.blue))
graph1 = customPlot.addGraph()
graph1.setPen(QPen(Qt.red))
x, y0, y1 = [], [], []
for i in range (251):
x.append(i)
y0.append(math.exp(-i/150.0)*math.cos(i/10.0))
y1.append(math.exp(-i/150.0))
graph0.setData(x, y0)
graph1.setData(x, y1)
customPlot.rescaleAxes()
customPlot.setInteractions(QCP.Interactions(QCP.iRangeDrag | QCP.iRangeZoom | QCP.iSelectPlottables))
customPlot.setGeometry(400, 250, 542, 390)
customPlot.show()
sys.exit(app.exec_())