Created
November 26, 2015 09:57
-
-
Save electronut/332b9097179f33c7fcd7 to your computer and use it in GitHub Desktop.
A simple python matplotlib animation example that shows an oscillating circle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
oscillating_circle.py | |
A simple matplotlib animation example that shows an oscillating circle. | |
electronut.in | |
""" | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
import math | |
import numpy as np | |
count = 0 | |
def update(frameNum, a0): | |
global count | |
A = math.sin(math.radians(count)) | |
x = [A*math.cos(a) for a in np.arange(0, 2*math.pi+0.1, 0.1)] | |
y = [math.sin(a) for a in np.arange(0, 2*math.pi+0.1, 0.1)] | |
a0.set_data(x, y) | |
count = (count + 1) % 360 | |
fig = plt.figure() | |
ax = plt.axes(xlim=(-1, 1), ylim=(-1, 1)) | |
a0, = ax.plot([], []) | |
anim = animation.FuncAnimation(fig, update, | |
fargs=(a0,), | |
interval=20) | |
# show plot | |
plt.show() |
Hi,
this code works really well. Do you by any chance know how to modify your code to animate two 3D lines defined by x, y and z coordinates of their start and end points - where these coordinates are changing in time?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what it looks like: