애니메이션을 사용하여 Matplotlib로 플롯 제목을 업데이트하려면 다음 단계를 수행할 수 있습니다. -
- 그림 크기를 설정하고 서브플롯 사이 및 주변 여백을 조정합니다.
- Figure()를 사용하여 새 Figure 생성 또는 기존 Figure 활성화 방법.
- x 만들기 및 y numpy를 사용한 데이터 포인트
- 현재 축을 가져옵니다.
- text()를 사용하여 축에 텍스트 추가 방법.
- 함수를 반복적으로 호출하여 애니메이션을 만드는 데 사용할 수 있는 애니메이션 메서드를 추가합니다.
- 그림을 표시하려면 show()를 사용하세요. 방법.
예시
import numpy as np
from matplotlib import pyplot as plt, animation
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
x = np.linspace(-10, 10, 1000)
y = np.sin(x)
plt.plot(x, y)
ax = plt.gca()
ax.text(0.5, 1.100, "y=sin(x)", bbox={'facecolor': 'red',
'alpha': 0.5, 'pad': 5},
transform=ax.transAxes, ha="center")
def animate(frame):
ax.text(0.5, 1.100, "y=sin(x), frame: %d" % frame,
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 5},
transform=ax.transAxes, ha="center")
ani = animation.FuncAnimation(fig, animate, interval=100,
frames=10, repeat=True)
plt.show() 출력
