Python Qt中添加GroupBox后进行plt绘图

1、在Qt Designer中打开ui文件,在ui文件中通过Qt Designer拖入GroupBox;

2、在Pycharm中设置External Tools添加ui转py命令,将ui文件转为py文件;

3、在执行的py文件中添加绘图命令:

    def plotTest(self):
        vbox = QVBoxLayout(self.plotBox)
        fig = Figure(facecolor='#132E35')  # 设置Figure的背景颜色
        self.canvas = FigureCanvas(fig)
        vbox.addWidget(self.canvas)

        ax = fig.add_subplot(111)
        ax.plot([1, 2, 3, 4], [10, 20, 25, 30], '-o')
        ax.set_title('Simple Line Plot', color='white')  # 设置标题颜色为白色
        ax.set_facecolor('#132E35')  # 设置背景颜色为#132E35
        ax.tick_params(axis='x', colors='white')  # 设置x轴刻度颜色为白色
        ax.tick_params(axis='y', colors='white')  # 设置y轴刻度颜色为白色

        fig.subplots_adjust(left=0.1, right=0.9, top=0.8, bottom=0.2)  # 手动调整子图位置,规避绘图被groupBox遮挡

你可能感兴趣的:(python,qt,开发语言)