matplotlibアニメーション関数を使ってpython3で複数のオブジェクトを同時にアニメーション化しようとしています。matplotlibを使ってpython3で複数の図形をアニメーション化する
ここに書かれているコードは、ここまでです。私は複数のオブジェクトを作成し、それらを図に表示することができます。私は、矩形のパッチ関数を含むforループを使用してこれを行いました。ここからは、アニメーション機能を使用して、すべての個々の矩形を一定量だけ移動させたいと考えていました。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(111)
plt.xlim(-100, 100)
plt.ylim(-100, 100)
width = 5
bars = 25
RB = [] # Establish RB as a Python list
for a in range(bars):
RB.append(patches.Rectangle((a*15-140,-100), width, 200,
color="blue", alpha=0.50))
def init():
for a in range(bars):
ax.add_patch(RB[a])
return RB
def animate(i):
for a in range(bars):
temp = np.array(RB[i].get_xy())
temp[0] = temp[0] + 3;
RB[i].set_XY = temp
return RB
anim = animation.FuncAnimation(fig, animate,
init_func=init,
frames=15,
interval=20,
blit=True)
plt.show()
現在のところ、コードを実行すると、何も動きません。私はpythonのウェブサイトにある例に従おうとしました。通常、 'AttributeError:' list 'オブジェクトには属性' set_animated 'がありません。あなたが代わりにRBでset_XY = temp
あなたはそれが 'set_XY = temp'なければならないと確信している - の例にない' set_XY(TEMP) ' – furas
プット・リンク。そして、常に最後の部分だけでなく、完全なエラーメッセージ(Traceback)を質問に入れてください。その他の有用な情報があります。すなわち、どのラインが問題になるか。 – furas