2014-11-04 64 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