1

I am struggling to animate a 3d graph using python. I want the code to draw the graph frame by frame, so that I know the movement of the subject by time. (I'm using motion analysis data and I'm trying to graph the movement of a subject.) All my data is stored in a csv file, which I configured to a 3*200 array. (3 columns for x, y, z axis; data4) Here is my code:

import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.animation as animation

df = pd.DataFrame(data4, columns = ["x", "y", "z"])
fig = plt.figure()
ax = fig.add_subplot(111, projection = "3d")
def update(i):
    offsets3d = (df.x.values[:i], df.y.values[:i], df.y.values[:i])

ax.set_xlim(-500,500)
ax.set_ylim(-500,500)
ax.set_zlim(-500,500)

ani = animation.FuncAnimation(fig, update, frames =len(df), interval = 250)

plt.show()
felixtep
  • 11
  • 3
  • There are already many posts on this site with answers to the exact same question (For example, [this one](https://stackoverflow.com/questions/38118598/3d-animation-using-matplotlib)). The documentation of maplotlib also provides [an example with everything you need](https://matplotlib.org/examples/animation/simple_3danim.html). – Diziet Asahi Sep 26 '17 at 10:15

0 Answers0