我正在用Python编写软件.我需要将Matplotlib时间动画嵌入到自制的GUI中.以下是有关它们的更多详细信息:
GUI也是用Python编写的,使用PyQt4库.我的GUI与您在网上可以找到的常见GUI没有太大区别.我只是继承QtGui.QMainWindow并添加一些按钮,布局,......
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)