Trajectary For A Buoy Flow In The Tasman Sea With Tail
Im trying to make a plot the path of a buoy in the tasman sea. I got the buoy flowing around but I cannot find how i can give it a tail of the previous 5 steps. fig, ax = plt.subp
Solution 1:
You could slice the current location plus the five previous locations from the data, e.g. for step i
you plot data[i:i+5]
. You need to handle beginning and end of the data.
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
ax.set_xlim(0, 100)
x = np.arange(100)
y = np.random.rand(100)
# initialization function: plot the background of each framedefinit():
line.set_data([], [])
return line,
# animation function. This is called sequentiallydefanimate(i):
_x = x[i: i+5]
_y = y[i: i+5]
print(_x,_y)
line.set_data(_x, _y)
return line,
# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval=20, blit=True)
plt.show()
Example from https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/
Post a Comment for "Trajectary For A Buoy Flow In The Tasman Sea With Tail"