一段时间后,我设法通过直接使用基础函数而不是使用动画包装器来重新创建动画:
import sysfrom PyQt4 import QtGui, QtCorefrom matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvasfrom matplotlib.figure import Figurefrom matplotlib.patches import Circlefrom matplotlib import animationfrom time import sleepclass Window(QtGui.QDialog): #or QtGui.QWidget ??? def __init__(self): super(Window, self).__init__() self.fig = Figure(figsize=(5, 4), dpi=100) self.canvas = FigureCanvas(self.fig) self.ax = self.fig.add_subplot(111) # create an axis self.ax.hold(False) # discards the old graph self.ax.set_aspect('equal', 'box') self.circle = Circle((0,0), 1.0, animated=True) self.ax.add_artist(self.circle) self.ax.set_xlim([0, 10]) self.ax.set_ylim([-2, 2]) self.button = QtGui.QPushButton('Animate') self.button.clicked.connect(self.animate) # set the layout layout = QtGui.QVBoxLayout() layout.addWidget(self.canvas) layout.addWidget(self.button) self.setLayout(layout) self.canvas.draw() self.ax_background = self.canvas.copy_from_bbox(self.ax.bbox) def animate(self): self.animate_loop(0) def animate_loop(self,begin): for i in range(begin,10): self.canvas.restore_region(self.ax_background) self.circle.center=(i,0) self.ax.draw_artist(self.circle) self.canvas.blit(self.ax.bbox) self.canvas.flush_events() sleep(0.1)def main(): app = QtGui.QApplication(sys.argv) ex = Window() ex.show() sys.exit(app.exec_())if __name__ == '__main__': main()
也许这对您有用。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)