Я смотрю много часто встречающихся тем на Stackoverflow, но никто не может реально помочь мне.
Моя цель - анимировать прямоугольники внутри для l oop.
from matplotlib import pyplot as plt
from matplotlib import animation
import matplotlib.path as mpath
import matplotlib.patches as mpatches
class rectangle:
def __init__(self):
self.fig = plt.figure(figsize=(12, 9), dpi=80, facecolor='w', edgecolor='k')
self.ax = self.fig.add_subplot(111, autoscale_on=False)
self.ax.set_xlim(-10, 50)
self.ax.set_ylim(-5, 5)
def drawrect(self, new_position):
verts = [
[0, 0],
[0.5, 0],
[0.5, 0.5],
[0, 0.5]
]
for vert in verts:
vert[0] = vert[0] + new_position
path = mpath.Path(verts)
patch = mpatches.PathPatch(path, facecolor="g", edgecolor="r")
self.ax.add_patch(patch)
# Main Programm
Myrect = rectangle()
for x in range(10):
Myrect.drawrect(x)
# Doing other stuff
print(x)
print("will this execute after animate or between every rectangle?")
#anim = animation.FuncAnimation(Myrect.fig, Myrect.drawrect(x))
plt.show()
актуально результат: введите описание изображения здесь
Где я должен добавить matplotlib.animation.FuncAnimation () и какие параметры использовать?