将条形图添加到小部件容器

时间:2019-06-26 16:58:53

标签: matplotlib pyqt5 qt-designer

我可以将规则图添加到容器中,而不能添加条形图。

Ui_MainWindow, QMainWindow = loadUiType('window.ui')

class Main(QMainWindow, Ui_MainWindow):
    def __init__(self, ):
        super(Main, self).__init__()
        self.setupUi(self)

    def addmpl(self, fig):
        self.canvas = FigureCanvas(fig)
        self.mplvl.addWidget(self.canvas)
        self.canvas.draw()


if __name__ == '__main__':
    import sys
    from PyQt5 import QtWidgets
    import numpy as np


    names = ["Bob", "Jerry", "Craig"]
    scores = [75, 86, 99]
    positions = [0, 1, 2]
    plt.title("Student Test Results")
    plt.xlabel("Students")
    plt.ylabel("Scores")
    plt.bar(positions, scores, label="Test 1", width=0.3, color="g")

    fig1 = Figure()
    ax1f1 = fig1.add_subplot(111)
    ax1f1.plot()

    app = QtWidgets.QApplication(sys.argv)
    main = Main()
    main.addmpl(fig1)
    main.show()
    sys.exit(app.exec_())

我得到的错误是“参数必须是数字或字符串,而不是'矩形'”

0 个答案:

没有答案