0

I want to animate circles and lines with matplotlib. I was able to to this with circles, but not with lines. The following code works for the circles(without the line parts). With the line-parts, matplotlib just opens a white window.

#imports...
#create figure called ax

mypatch[0] = plt.Circle((0, 0), 0.75, fc='y')
mypatch[1] = plt.Circle((0, 0), 0.75, fc='y')
#... more patches

myline[0] = lin.Line2D([0,0],[0,0],color='b')
myline[1] = lin.Line2D([0,0],[0,0],color='b')
#... more lines

def init():
    ax.add_patch(mypatch[0])
    ax.add_patch(mypatch[1])
    #...
    ax.add_line(myline[0])
    ax.add_line(myline[1])
    #...
    return mypatch, myline

def animate(i):
    #trajectory of mypatch and myline
    return mypatch, myline

anim = anmiation.FuncAnimation(fig, animate, init_func=init,...)
plt.show()

1 Answer 1

1

The lines go from (0,0) to (0,0) so there's nothing to plot.

Something like the following will make lines show up in your example:

myline[0] = Line2D([0,1],[0,1],color='b')
myline[1] = Line2D([0,1],[0,0.8],color='b')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.