이 문제를 묻기 위해 코드를 정리 한 다음 정리하는 동안 해결책을 찾았습니다. 아래 내 솔루션을 참조하십시오.imshow() 및 matplotlib.patches를 사용하여 동적 이미지의 빠른 정적 서클
나는 동적 영상 (동영상)을 matplotlib.patches
을 사용하여 그 위에 그려진 정적 원을 사용하여 만들려고 시도하고 있지만 동영상이 재생 될 때 속도가 느려집니다 (대기 시간은 시간에 따라 선형 적으로 증가합니다). 서클은 고정되어 있으므로 imshow()
이 업데이트됨에 따라 matplotlib.patches
이 더 빠르게 실행되도록하는 방법이 있어야합니다. 여기 내 코드는 다음과 같습니다.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Circle
from scipy.linalg import toeplitz
# Radius for circle of circles
r = 0.5
# Number of circles
n = 7
# Locations of centers of circles
a = r*np.transpose(np.array([np.cos(np.arange(0,2*np.pi,2*np.pi/n)),
np.sin(np.arange(0,2*np.pi,2*np.pi/n))]))
# Create first background image.
E = toeplitz(np.random.rand(70))
# Plot the first frame.
fig = plt.figure(1)
ax = fig.add_subplot(111)
im = ax.imshow(E,extent=np.array([-1,1,-1,1]))
# Draw the circles on the image
for k in range(np.shape(a)[0]):
ax.add_patch(Circle((a[k][0],a[k][1]),0.1))
plt.show()
# Update with background image and redraw the circles.
for t in range(60):
# Update the background image.
E=toeplitz(np.random.rand(70))
im.set_array(E)
# Update the circles
for k in range(np.shape(a)[0]):
ax.add_patch(Circle((a[k][0],a[k][1]),0.1))
fig.canvas.draw()