MATLAB: How to set axis of scatter3

3d plotsaxisdataplotscatter3

Hi, I have a for loop that basically continuously plots points using drawnow corresponding to particles in an explosion. So far, I've got the 3D scatter plot to continuously graph the explosion, its just that the axis continually readjusts every couple iterations, and the point motion is distorted because of it. Is there any way to set the axis of scatter3D? I've checked online everywhere and couldn't find an answer. Axis() doesn't seem to do anything. Thanks

Best Answer

Here is an example with unfixed axes, and fixed axes:
% Unfixed axes
figure
for N = 1:10
pause(0.5)
[X,Y,Z] = sphere(16);
r = rand(1);
X = 5*r*X;
Y = 5*r*Y;
Z = 5*r*Z;
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
scatter3(x,y,z)
end
% Fixed axes
figure
for N = 1:10
pause(0.5)
[X,Y,Z] = sphere(16);
r = rand(1);
X = 5*r*X;
Y = 5*r*Y;
Z = 5*r*Z;
x = [0.5*X(:); 0.75*X(:); X(:)];
y = [0.5*Y(:); 0.75*Y(:); Y(:)];
z = [0.5*Z(:); 0.75*Z(:); Z(:)];
scatter3(x,y,z)
set(gca,'XLim',[-3 3],'YLim',[-3 3],'ZLim',[-3 3])
end
Related Question