How to halt matlab plot3 scale

拥有回忆 提交于 2019-12-02 06:44:11

问题


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.


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/53450296/how-to-halt-matlab-plot3-scale

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!