如何停止Matlab plot3比例尺 [英] How to halt matlab plot3 scale
问题描述
我想使用plot3
函数绘制摆锤(改变位置).不幸的是,当我的点在循环中改变位置并再次绘制时,3d图的比例也在改变,因此x轴取决于位置的变化(取决于点的位置,它可以从-1到-1.5或从-1至-3)和y也改变.只有z表示相同.结果是点跳到图形上而不会产生摆的印象.这是我的情节:
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
或
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.
推荐答案
这里是2D的简短示例,您也可以轻松地将其应用于3D:
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
此处的关键是在循环之前设置xlim
,然后仅更新绘图中的相关数据(在这种情况下,使用XData
).
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).
这篇关于如何停止Matlab plot3比例尺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!