2014-11-04 63 views
0

我希望我的图形能够固定坐标轴,并且还可以逐个绘制数据。所有的东西都是已知的,但是如果我使用暂停来移除第一组数据,它也会忘记轴上的限制并自动为第二组数据分配新的限制。 是否有可能在每次将单独的数据块绘制在同一图中时保持坐标轴一致?仅保留坐标轴,而不保存数据

现在的代码是:

figure(4) 
grid on 
axis([xL yL zL]) 
for j = 1:n  % n is amount of data sets 
    for i = 1:2 % two items drawn per data set 
     *plot data* 
     hold on 
    end 

    %This part has to be done every iteration again in order to make it work now 
    axis([xL yL zL]) 
    xlabel = ... 
    ylabel 
    zlabel 
    title 

pause(tstop) 
hold off 
end 

某些搜索唯一相关的话题我发现后, Matlab: Plot a subplot with hold on and hold off in a loop without always calling xlabel, ylabel, xlim, etc 但是我完全不理解它。它使用父母形象,替代孩子,nextplot等我不熟悉的东西,也找不到更多的信息。

+0

这是可以做到。请发布您的代码(或者最低工作示例),以便我们可以提出解决方案 – 2014-11-04 23:55:43

回答

1

下面是可以很容易地适应您的需求的例子:

xlim([0 10]) %// set x-axis limits 
ylim([0 10]) %// set y-axis limits 
set(gca,'nextplot','replacechildren') %// prevent axis limits from changing with 
%// each new plot 

plot(3:8,3:8); %// note axis limits are kept as [0 10] 
pause(1) 
plot(5:7,5:7); %// note axis limits are kept as [0 10] 
+1

我相信使用'(x | y)lim('manual')'是多余的 - 使用'xlim'和'ylim'手动设置限制函数自动将'(x | y)limmode'值设置为'manual'。 – MrAzzaman 2014-11-05 01:08:10

+0

@MrAzzaman好点!更正 – 2014-11-05 10:08:25