0
この問題を尋ねるためにコードを整理し、解決している間に解決策を見つけました。以下の私の解決策を見てください。imshow()とmatplotlib.patchesを使用したダイナミックイメージの高速静的円
matplotlib.patches
を使用して静的な円を描いたimshow()
の動画(動画)を作成しようとしていますが、ムービーの再生速度が遅くなります(待ち時間は時間とともに直線的に増加しています)。サークルは静的なので、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()