0

I'm trying to find a way to dynamically update a 3d scatter plot. I found this post about a dynamically updated 2d plot and I was able to get the code working on my machine without any tweaking. But when trying to adapt it to work for a 3d plot I'm having some trouble. Here's my code:

import numpy as np
import matplotlib.animation as ani
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig, sa, sb, l, a, b, z, x = None, None, None, None, None, None, None, None
devices = []
a=2


def animate(i):
    global a
    x.append(a)
    y.append(a)
    z.append(a)
    sc.set_offsets(np.c_[x,y,z])
    a += 1

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim3d(0, 10)
ax.set_ylim3d(0, 10)
ax.set_zlim3d(0, 10)

plt.subplots_adjust(left=0.25, bottom=0.25)

x = [1]
y = [1]
z = [1]
sc = ax.scatter(x,y,z)

animation = ani.FuncAnimation(fig, animate, frames=2, interval=100)

plt.show()

When I run this, a 3d plot pops up with a single point plotted and no animation. Anyone have any idea what's broken with this code? Thanks!

Padaca
  • 337
  • 1
  • 6
  • 1
    Yep, refer to [matplotlib-3d-scatter-animations](https://stackoverflow.com/questions/41602588/matplotlib-3d-scatter-animations) instead. – ImportanceOfBeingErnest Aug 12 '19 at 14:35
  • Wow, no idea how I didn't see this when I was searching earlier. It was a simple matter of using an offsets function that was 3d-friendly, thanks for the help Ernest! – Padaca Aug 12 '19 at 16:32

0 Answers0