相关疑难解决方法(0)

您自己的PyQt4 GUI中的Matplotlib动画

我正在用Python编写软件.我需要将Matplotlib时间动画嵌入到自制的GUI中.以下是有关它们的更多详细信息:

1. GUI

GUI也是用Python编写的,使用PyQt4库.我的GUI与您在网上可以找到的常见GUI没有太大区别.我只是继承QtGui.QMainWindow并添加一些按钮,布局,......

2.动画

Matplotlib动画基于animation.TimedAnimation类.这是动画的代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import matplotlib.animation as animation

        class CustomGraph(animation.TimedAnimation):

        def __init__(self):

            self.n = np.linspace(0, 1000, 1001)
            self.y = 1.5 + np.sin(self.n/20)
            #self.y = np.zeros(self.n.size)


            # The window
            self.fig = plt.figure()
            ax1 = self.fig.add_subplot(1, 2, 1)
            self.mngr = plt.get_current_fig_manager() 
            self.mngr.window.setGeometry(50,100,2000, 800)

            # ax1 settings
            ax1.set_xlabel('time')
            ax1.set_ylabel('raw data')
            self.line1 = Line2D([], [], color='blue')
            ax1.add_line(self.line1)
            ax1.set_xlim(0, 1000)
            ax1.set_ylim(0, 4)


            animation.TimedAnimation.__init__(self, self.fig, interval=20, blit=True)


        def …
Run Code Online (Sandbox Code Playgroud)

python animation pyqt matplotlib pyqt4

6
推荐指数
1
解决办法
6460
查看次数

标签 统计

animation ×1

matplotlib ×1

pyqt ×1

pyqt4 ×1

python ×1