I have the following code.
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.ion()
plt.show()
mapping = defaultdict(partial(deque, maxlen=10))
My mapping structure contains a queues with x, y, z values. I want to plot only the point in queue so as the queue changes the plot should also change. How would I do that?
Note: This is challenging because the queue is of a bounded size and the plot has to reflect only whats in the queue.
The hacky way to do this is:
which removes the line with the old data and adds one with the new data.
If you are willing to write code that depends on the internals of
matplotlib(which is a bad idea as the internal will likely change under you), you can also do this by:Patch here for added a function to do this: https://github.com/matplotlib/matplotlib/pull/1629
The animation module nicely wraps up many of the things needed to do animation (including a way to stream output directly to ffmpeg), and there is a very nice tutorial.
Line3Ddocs,Line2Ddocs