Matlab问题:这可能很简单,但我无法弄明白......我很新。我有一个绘图窗口,分为两个子图,让我们称它们为A和B,它们有不同的标签和限制。我(坚持),给B做几个图,然后我(推迟),然后开始迭代。在循环中,我想用NEW图来更新A和B,但是我想要轴标签,xlim和ylim保持不变,而不必每次迭代都调用xlabel,xlim等。
现在,(延迟)会破坏所有轴属性。如何保存轴属性,以便我不必在循环中继续调用xlabel等?我试过newplot,设置Nextplot属性等无济于事。我想要一个简单的解决方案...而不是重写剧情命令。谢谢!
hfig=figure();
hax = axes('Parent',hfig);
plot(hax,x,y);
hold on
plot(hax,x1,y1);
%this hold off resets the axes
hold off
while (1)
subplot('Position',[.07 .05 .92 .44]);
%I want to do this without having to call xlabel, ylabel, etc
%over and over
plot(newx, newy);
xlabel()
ylabel()
hold on
plot(newx1, newx2)
hold off
...
end
答案 0 :(得分:2)
这里的一个解决方案是在循环之前初始化绘图和轴属性,然后在循环内将轴的'NextPlot'
property设置为'replacechildren'
,这样只有绘图对象(而不是轴设置) )将在下次调用PLOT时更改:
hFigure = figure();
hAxes = axes('Parent',hFigure);
plot(hAxes,x,y);
hold on;
plot(hAxes,x1,y1);
xlabel(...); %# Set the x label
ylabel(...); %# Set the y label
xlim([...]); %# Set the x limits
ylim([...]); %# Set the y limits
while (1)
set(hAxes,'NextPlot','replacechildren');
plot(hAxes,newx,newy);
hold on;
plot(hAxes,newx1,newx2);
...
end
当在循环中绘制新数据时,这应保持hAxes
的设置。