避免图形在 MATLAB 中连续弹出
Avoid figure popping up continuously in MATLAB
如何避免 MATLAB 在循环内绘制数据时弹出带有两个轴的 GUI 图 f
。
这是一个简单的例子:
f=figure;
ax.h1 = axes('Parent',f,'Position',[0.1 0.1 0.8 0.35],'Units','normalized');
ax.h2 = axes('Parent',f,'Position',[0.1 0.6 0.8 0.35],'Units','normalized');
for j=1:20
axes(ax.h1)
hold on
plot(1:3,(1:3)+j)
axes(ax.h2)
hold on
plot(1:3,(1:3)+1+j)
pause(2)
end
我需要持续绘制数小时的数据。因此,如果每次生成新图时 MATLAB 都没有弹出,那就太好了。
谢谢!
正如@TasosPapastylianou 指出的那样,axis
调用将 window 带到了前面。删除循环内的 axis
和 hold on
调用并使用 plot(ax.h1, ...
绘制到特定轴。您只需要为每个轴调用一次 hold on
,所以在开始时使用 hold(ax.h1, 'on')
等执行此操作。然后您的图表应该在后台继续更新,而不是每次都出现在前面。
您的示例变为:
f=figure;
ax.h1 = axes('Parent',f,'Position',[0.1 0.1 0.8 0.35],'Units','normalized');
ax.h2 = axes('Parent',f,'Position',[0.1 0.6 0.8 0.35],'Units','normalized');
hold(ax.h1, 'on')
hold(ax.h2, 'on')
for j=1:20
plot(ax.h1, 1:3,(1:3)+j)
plot(ax.h2, 1:3,(1:3)+1+j)
pause(2)
end
如何避免 MATLAB 在循环内绘制数据时弹出带有两个轴的 GUI 图 f
。
这是一个简单的例子:
f=figure;
ax.h1 = axes('Parent',f,'Position',[0.1 0.1 0.8 0.35],'Units','normalized');
ax.h2 = axes('Parent',f,'Position',[0.1 0.6 0.8 0.35],'Units','normalized');
for j=1:20
axes(ax.h1)
hold on
plot(1:3,(1:3)+j)
axes(ax.h2)
hold on
plot(1:3,(1:3)+1+j)
pause(2)
end
我需要持续绘制数小时的数据。因此,如果每次生成新图时 MATLAB 都没有弹出,那就太好了。
谢谢!
正如@TasosPapastylianou 指出的那样,axis
调用将 window 带到了前面。删除循环内的 axis
和 hold on
调用并使用 plot(ax.h1, ...
绘制到特定轴。您只需要为每个轴调用一次 hold on
,所以在开始时使用 hold(ax.h1, 'on')
等执行此操作。然后您的图表应该在后台继续更新,而不是每次都出现在前面。
您的示例变为:
f=figure;
ax.h1 = axes('Parent',f,'Position',[0.1 0.1 0.8 0.35],'Units','normalized');
ax.h2 = axes('Parent',f,'Position',[0.1 0.6 0.8 0.35],'Units','normalized');
hold(ax.h1, 'on')
hold(ax.h2, 'on')
for j=1:20
plot(ax.h1, 1:3,(1:3)+j)
plot(ax.h2, 1:3,(1:3)+1+j)
pause(2)
end