BlackHawk3
BlackHawk3

Reputation: 349

How to halt matlab plot3 scale

I want to plot pendulum (which changes position) using plot3 function. Unfortunately, when my dot changes position in loop and is being plotted again, the scale of 3d plot is changing too, so the x axis depending on position changes (depending on position of the dot it can be from -1 to -1.5 or from -1 to -3) and y changes also. Only z states the same. The result is that the dot jumps on graph and does not create impression of pendulum. This is how I plot:

plot3(0,0,0);
daspect([1,1,1]);
axis([-10, 10, -10, 10]);
scatter3(x(i)-rs, y(i)-rs, 0);

I tried to deal with the problem using:

gca

or

set(fig, 'PaperPositionMode', 'auto');

but both do not help. I am also not able to rotate the graph, because it is being plotted and comes back to previous position.

Upvotes: 1

Views: 154

Answers (2)

EBH
EBH

Reputation: 10450

Here is a short example in 2D, you can easily apply this also to 3D:

N = 50;
x = [1:N;N:-1:1];
x = repmat(x,2,1).';
p = plot(x(1),1,'ob','MarkerFaceColor','b');
xlim([0 51])
for k = 2:numel(x)
    p.XData = x(k);
    drawnow
end

The key here is to set xlim before the loop, and then only update the relevant data in the plot (using XData in this case).

Upvotes: 0

Azim J
Azim J

Reputation: 8290

Try setting the XLim, YLim, and ZLim properties before plotting. For example,

xlim=[-1 1];

or

haxe = gca;
haxe.XLim = [-1 1];

Also, you could set XLimMode, YLimMode, and ZLimMode properties to manual. For example,

haxe.XLimMode = 'manual'

For more information regarding axis properties see MATLAB's documentation for axis properties.

Upvotes: 0

Related Questions