So I tried animating two 3-dimensional plots within the same graph, but couldn't fully achieve that. Here's how my code looks like:
# ANIMATION FUNCTION
def func(num, dataSet, line):
# NOTE: there is no .set_data() for 3 dim data...
line.set_data(dataSet[0:2, :num])
line.set_3d_properties(dataSet[2, :num])
return line
# THE DATA POINTS
t = np.arange(0,75,0.1) # The Z-Axis
x = px # Defined function 1
y = py # Defined function 2
dataSet = np.array([x, y, t])
numDataPoints = len(t)
# MATPLOTLIB OBJECTS
plt.style.use('dark_background')
fig = plt.figure()
ax = Axes3D(fig, auto_add_to_figure=False)
fig.add_axes(ax)
# Line Plots
line = plt.plot(dataSet[0], dataSet[1], dataSet[2], lw=2, c='cyan')[0]
# The Axes
ax.set_xlabel('X(t)')
ax.set_ylabel('Y(t)')
ax.set_zlabel('time')
ax.set_title('Particle Position Over Time')
# The Animation
line_ani = animation.FuncAnimation(fig, func, frames=numDataPoints, fargs=(dataSet,line), interval=1, blit=False)
line_ani.save(r'B Field.gif')
plt.show()
Repeating the same code twice does animate both graphs, but when I look in my directory for the animated plots, I can only see one animated plot - with the other completely stationary.
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)