在PyQt中,可以使用matplotlib
库来绘制折线图。
import sys from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget from matplotlib.figure import Figure from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas import numpy as np class MainWindow(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.setWindowTitle("Line plot example") layout = QVBoxLayout() self.widget = QWidget() self.widget.setLayout(layout) self.setCentralWidget(self.widget) self.figure = Figure() self.canvas = FigureCanvas(self.figure) layout.addWidget(self.canvas) self.axes = self.figure.add_subplot(111) # Generate random data x = np.linspace(0, 10, 100) y = np.sin(x) # Plot data self.axes.plot(x, y) # Set y axis range self.axes.set_ylim([-1, 1]) # 设置y轴的最小值为-1,最大值为1 self.canvas.draw() if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())
################################
标签:__,canvas,figure,self,axes,PyQt,折线图,import,绘制 From: https://www.cnblogs.com/herd/p/17701308.html