메모
전체 예제 코드를 다운로드 하려면 여기 를 클릭 하십시오.
애니메이션 일시 중지 및 재개 #
이 예는 다음을 보여줍니다.
- Animation.pause() 메서드를 사용하여 애니메이션을 일시 중지합니다. 
- Animation.resume() 메서드를 사용하여 애니메이션을 재개합니다. 
메모
이 예제는 Matplotlib의 대화형 기능을 실행하며 정적 문서에는 나타나지 않습니다. 상호 작용을 보려면 컴퓨터에서 이 코드를 실행하십시오.
개별 부분을 복사하여 붙여넣거나 페이지 하단의 링크를 사용하여 전체 예제를 다운로드할 수 있습니다.

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
class PauseAnimation:
    def __init__(self):
        fig, ax = plt.subplots()
        ax.set_title('Click to pause/resume the animation')
        x = np.linspace(-0.1, 0.1, 1000)
        # Start with a normal distribution
        self.n0 = (1.0 / ((4 * np.pi * 2e-4 * 0.1) ** 0.5)
                   * np.exp(-x ** 2 / (4 * 2e-4 * 0.1)))
        self.p, = ax.plot(x, self.n0)
        self.animation = animation.FuncAnimation(
            fig, self.update, frames=200, interval=50, blit=True)
        self.paused = False
        fig.canvas.mpl_connect('button_press_event', self.toggle_pause)
    def toggle_pause(self, *args, **kwargs):
        if self.paused:
            self.animation.resume()
        else:
            self.animation.pause()
        self.paused = not self.paused
    def update(self, i):
        self.n0 += i / 100 % 5
        self.p.set_ydata(self.n0 % 20)
        return (self.p,)
pa = PauseAnimation()
plt.show()