So I have a 3d live-updating graph! it only shows one point at a time so I can easily track the motion of the point! But here is the problem:
No matter what I seem to do
You probably want to hold your axis-ranges constant. This can be done, for example, by axis().
See also these answers:
How to set axis range
y-axis limit
enforce axis range
An Axes3D
object (your ax
variable) has the following methods: set_xlim
, set_ylim
, and set_zlim
. You could use these to fix the limits of your axes.
Documentation:
Edit
Using set_xlim
, etc, works for me. Here is my code:
#!python2
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
data = [
[-1.982905, 3.395062, 8.558263, '2012-01-18 14:00:03'],
[ 0.025276, -0.399172, 7.404849, '2012-01-18 14:00:04'],
[-0.156906, -8.875595, 1.925565, '2012-01-18 14:00:05'],
[ 2.643088, -8.307801, 2.382624, '2012-01-18 14:00:06'],
[3.562265, -7.875230, 2.312898, '2012-01-18 14:00:07'],
[4.441432, -7.907592, 2.851774, '2012-01-18 14:00:08'],
[4.124187, -7.854146, 2.727229, '2012-01-18 14:00:09'],
[4.199698, -8.135596, 2.677706, '2012-01-18 14:00:10'],
[4.407856, -8.133449, 2.214902, '2012-01-18 14:00:11'],
[4.096238, -8.453822, 1.359692, '2012-01-18 14:00:12'],
]
ion()
fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
ax.set_xlim((-10, 11))
ax.set_ylim((-10, 11))
ax.set_zlim((-10, 11))
lin = None
for x, y, z, t in data:
ax.set_title(t)
if lin is not None:
lin.remove()
lin = ax.scatter(x, y, z)
draw()
pause(0.1)
ioff()
show()
Edit 2
You could have a look at switching off autoscaling of axes which is on by default. Maybe this is overriding the set_lim
methods.
Documentation:
I ran into pretty much the exact same problem as you. I found one way to get it to work is to reset the axis limits each time you want to add a new point, so your loop would look something like:
while plotting:
df2 = df.ix[count]
count += 1
xs = df2['x.mean']
ys = df2['y.mean']
zs = df2['z.mean']
t = df2['time']
ax.set_title(t)
if lin is not None:
lin.remove()
lin = ax.scatter(xs, ys, zs)
ax.set_xlim((-10, 11))
ax.set_ylim((-10, 11))
ax.set_zlim((-10, 11))
draw()
pause(0.01)
if count > 100:
plotting = False
I have a feeling resetting the limits everytime is a bad way to solve this, so I asked a question about it, and will hopefully find an answer. If all you want is to just see something working, then hopefully the limit changes within the loop will do the trick